Extend a class that implements the Shadows interface name

Consider the following Typescript classes:

interface ITest {
  example(): string;
}

class A implements ITest {
  example() {
    return 'Test A';
  }
}

class B extends A {
  example() {
    return 'Test B';
  }
}

      

This translates to the following Javascript code (see http://www.typescriptlang.org/Playground ):

var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var A = (function () {
    function A() {
    }
    A.prototype.example = function () {
        return 'Test A';
    };
    return A;
})();
var B = (function (_super) {
    __extends(B, _super);
    function B() {
        _super.apply(this, arguments);
    }
    B.prototype.example = function () {
        return 'Test B';
    };
    return B;
})(A);

      

The code works correctly and gives the result

"Test A"
"Test B"

      

But checking this code with JSLint gives warning

One warning 17

'B' is already defined.

JsLint is having problems with __extends(B, _super)

. But of course it is necessary to extend the class. So how can I make sure JSLint doesn't complain when using inheritance in TypeScript?

+3


source to share


1 answer


Don't run lint on generated code. Lint is to enforce style and best practices in the source, so it should be run as input to any code generation tools. The output of these tools will rarely, if ever, be friendly enough to pile up, and this is not something you need to read or check anyway. When working with compiled languages, you run lint on source, not binary, and this is the JS equivalent.



You should use a tool like TSLint to check the Typescript before loading it into the TS compiler. If you are using Gulp (or Grunt) there are TSLint plugins ( gulp-tslint and grunt-tslint ).

+4


source







All Articles