VS Code抱怨TS7013错误,但没有Typescript

问题描述 投票:0回答:1

我在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以停止抱怨?

typescript visual-studio-code interface compiler-errors new-operator
1个回答
0
投票

VScode在tsconfig.json文件中配置了noImplicitAny: true时抱怨。也因为这是strict: true的默认设置。因此,如果要关闭它,则需要将其显式覆盖为noImplicitAny: false

您可以在official docs中查看详细的说明

但是,使此错误消失的更好方法是显式添加返回类型,理想情况下,强烈定义类型,甚至是any,使其比隐式变体更好。

export interface MyInterface {
  new (helper: MyInterfaceHelpers): any;
}
© www.soinside.com 2019 - 2024. All rights reserved.