microsoft / microsoft/TypeScript
Check inferred `this` parameter against interface requirement `this: void`
@sandersn 已经在做这个了。
开始于 2021年6月15日。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
Bug Report
🔎 Search Terms
interface method requirement this: void
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Foo {
method(this: void): number;
}
class Example implements Foo {
x = 3;
method() { return this.x; } // no error
}
🙁 Actual behavior
No error
🙂 Expected behavior
Error because the method implementation's implicit this: Example is not compatible with the interface requirement this: void.
The @typescript-eslint/unbound-method lint rule uses this: void as an annotation indicating the method is allowed to be used without binding this. However, there seems to be no checking from the TS compiler as to whether an inferred this type in a method implementation matches an interface requirement. Thus the lint rule can help you add this: void to the interface if you intend for functions to be usable when not bound... but neither the linter nor compiler currently help prevent runtime errors resulting from implementations with mismatched this types.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。