VS Code 抱怨错误 TS7013 但 Typescript 不是

VS Code is complaining about an Error TS7013 but Typescript isn't

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

当您在 tsconfig.json 文件中配置 noImplicitAny: true 时,

VScode 正在抱怨。也因为这是 strict: true 的默认设置。所以如果你想关闭它,你需要明确地将它覆盖为 noImplicitAny: false.

详细说明可以查看official docs

但是,消除此错误的更好方法是显式添加 return 类型,理想情况下是强定义类型,或者甚至只是 any,使其比隐式变体更好.

export interface MyInterface {
  new (helper: MyInterfaceHelpers): any;
}