我在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以停止抱怨?
VScode在tsconfig.json文件中配置了noImplicitAny: true
时抱怨。也因为这是strict: true
的默认设置。因此,如果要关闭它,则需要将其显式覆盖为noImplicitAny: false
。
您可以在official docs中查看详细的说明
但是,使此错误消失的更好方法是显式添加返回类型,理想情况下,强烈定义类型,甚至是any
,使其比隐式变体更好。
export interface MyInterface {
new (helper: MyInterfaceHelpers): any;
}