我的 Typescript/Angular 项目中有以下界面
export interface MyInterface {
new (helper: MyInterfaceHelpers);
}
当我编译项目时,Typescript 编译器完全没有错误。
然而 VSCode 用波浪线强调它并显示一个错误说:
Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.ts(7013)
为什么 VS Code 会提示而 Typescript 不会?错误检查的这种分歧发生在哪里?最后,如何让 VS Code 停止提示?
最佳答案
当您有 noImplicitAny: true
时,VScode 会提示在您的 tsconfig.json 文件中配置。也因为这是 strict: true
的默认设置。 .因此,如果要关闭它,则需要将其显式覆盖为 noImplicitAny: false
.
详细说明可以查看official docs
但是,消除此错误的更好方法是显式添加返回类型,理想情况下是强定义类型,甚至只是 any
,使其比隐式变化更好。
export interface MyInterface {
new (helper: MyInterfaceHelpers): any;
}
关于typescript - VS Code 提示错误 TS7013 但 Typescript 不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62247521/