【发布时间】:2019-06-15 08:02:23
【问题描述】:
我在编写打字稿代码时经常犯这种错误:
class Foo {
constructor() { }
public get isFoo(): boolean { return true; } // getter
public isBar(): boolean { return false; } // normal function
}
let foo = new Foo();
if (foo.isFoo) { // this is ok, getter returns true
console.log("it is foo");
}
// and here comes the mistake:
if (foo.isBar) { // <- isBar is defined, forgot to write ()
console.log("it is bar"); // this happens also
}
是否有可能针对此类错误获得某种 tslinter 或编译器警告?
【问题讨论】:
-
另外,我认为你的例子是错误的。
foo.isBar是吸气剂,而不是foo.isFoo。 -
哦,我交换了 foo 和 bar 忘记将 getter 移动到 foo。
-
我删除了我的评论以支持我的回答。
标签: typescript linter