typescript 参数隐式具有“任何”类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47848778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
parameter implicitly has an 'any' type
提问by Ronin
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.
我正在将 Visual Studio 代码用于打字稿项目,其中我使用了一些 3rd 方 npm js 库。其中一些不提供任何 ts 类型(types.d.ts 文件),因此每当我使用参数或变量而不指定它们的类型时,vs 代码的 linting 都会显示此错误:参数隐式具有“任何”类型。此外, ts 不会编译。
How can I prevent this from happening?
我怎样才能防止这种情况发生?
回答by Ronin
First, to make typescript tolerate parameters without declaring their type, edit the tsconfig.json
首先,要使打字稿容忍参数而不声明其类型,请编辑 tsconfig.json
// disable this rule:
// "strict": true,
// enable this rule:
"noImplicitAny": false
Second, install the tslint npm package as a prerequisite for the tslintvs code extension
二、安装tslint npm包作为tslintvs code扩展的先决条件
npm install -g tslint
Third, install the tslint vs code extension
三、安装tslint vs code扩展
回答by LLL
Specify the type: (callback:any) => { }
for example.
指定类型:(callback:any) => { }
例如。