首页 > 解决方案 > 如何在 TypeScript 中配置更严格的类型检查?

问题描述

我想要进行更严格的代码检查,并且我不想被允许拥有任何隐式的“任何”类型。因此我启用了"strict": true

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "strict": true
  },
  "include": ["./"]
}

如果我写这个函数:

const testing = () => console.log("test");

VSCode 自动通过它的用法推断返回类型:

const testing: () => void

有什么办法可以让这个更严格并且不允许 VSCode 自动推断?

谢谢

标签: typescriptvisual-studio-codevscode-settingstypescript-typings

解决方案


emmm,在这种情况下,您最好使用 eslint 而不是 hacking ts,请参见此处:

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md


推荐阅读