打字稿是否可以选择禁止“任何"?在声明或转换/转换时? [英] Does typescript have an option to disallow "any" when declaring or cast/conversion?
本文介绍了打字稿是否可以选择禁止“任何"?在声明或转换/转换时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Visual Studio 2015 中使用 TypeScript 1.8.10 版.
I'm using TypeScript version 1.8.10 in Visual Studio 2015.
在 tsconfig.json 我有这些设置
In tsconfig.json I have those settings as
"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"?
I'm wondering is is there a setting that disallow the use of "any" and force us to use datatype such as number, string, etc. instead of "any"?
推荐答案
您可以将 TSLint 与 TypeScript 结合使用并设置 no-any
标志.请参阅 https://www.npmjs.com/package/tslint
You could use TSLint in conjunction with TypeScript and set the no-any
flag. See https://www.npmjs.com/package/tslint
还有带有 no-explicit-any
规则.
There's also ESLint with the no-explicit-any
rule.
这篇关于打字稿是否可以选择禁止“任何"?在声明或转换/转换时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文