【问题标题】:Does typescript have an option to disallow "any" when declaring or cast/conversion?typescript 在声明或强制转换/转换时是否可以选择禁止“任何”?
【发布时间】:2016-04-27 19:09:31
【问题描述】:

我在 Visual Studio 2015 中使用 TypeScript 版本 1.8.10。

在 tsconfig.json 我有这些设置

"compilerOptions": {
  "target": "es6",
  "module": "system",
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "removeComments": true,
  "noImplicitAny": true,
  "noEmitOnError": false,
  "noImplicitUseStrict": false,
  "declaration": false,
  "inlineSourceMap": true,
  "inlineSources": true
},

我想知道是否存在不允许使用“any”并强制我们使用数字、字符串等数据类型而不是“any”的设置?

【问题讨论】:

    标签: typescript visual-studio-2015


    【解决方案1】:

    您可以将 TSLint 与 TypeScript 结合使用并设置 no-any flag。见https://www.npmjs.com/package/tslint

    还有带有 no-explicit-any 规则的 ESLint。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多