javascript - Extend class that implements Interface shadows name -
consider following typescript classes:
interface itest { example(): string; } class implements itest { example() { return 'test a'; } } class b extends { example() { return 'test b'; } } this translates following javascript code (see http://www.typescriptlang.org/playground):
var __extends = this.__extends || function (d, b) { (var p in b) if (b.hasownproperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; var = (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 runs correctly , gives result
"test a" "test b" but checking code jslint gives warning
one warning 17
'b' defined.
jslint seems have problems __extends(b, _super). of course necessary extending class. how can make sure jslint not complain when using inheritance in typescript?
don't run lint on generated code. lint enforce style , best practices on source, should run on input code-generating tools. output of tools rarely, if ever, friendly enough lint , it's not need read or validate anyway. when working compiled languages run lint on source rather binary , js equivalent.
you should use tool tslint check typescript before feeding ts compiler. if you're using gulp (or grunt) there tslint plugins (gulp-tslint , grunt-tslint).
Comments
Post a Comment