参数隐式具有“任何"类型 [英] parameter implicitly has an 'any' type
问题描述
我正在将 Visual Studio 代码用于打字稿项目,其中我使用了一些 3rd 方 npm js 库.其中一些不提供任何 ts 类型(types.d.ts 文件),因此每当我使用参数或变量而不指定它们的类型时,vs 代码的 linting 都会显示此错误:参数隐式具有任何"类型.此外,ts 不会编译.
I'm using visual studio code for a typescript project, where I use some 3rd party npm js libraries. Some of them don't provide any ts types (types.d.ts file), so whenever I use parameters or variables without specifying their type, vs code's linting shows this error: parameter implicitly has an 'any' type. Also, ts wouldn't compile.
如何防止这种情况发生?
How can I prevent this from happening?
推荐答案
首先,要使 typescript 容忍参数而不声明其类型,请编辑 tsconfig.json
First, to make typescript tolerate parameters without declaring their type, edit the tsconfig.json
// disable this rule:
// "strict": true,
// enable this rule:
"noImplicitAny": false
其次,安装 tslint npm 包作为 tslint vs 代码扩展的先决条件
Second, install the tslint npm package as a prerequisite for the tslint vs code extension
npm install -g tslint
第三,安装tslint vs代码扩展
这篇关于参数隐式具有“任何"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!