Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameter implicitly has an 'any' type

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?

like image 725
Ronin Avatar asked Dec 16 '17 18:12

Ronin


People also ask

How do you fix this implicitly has type any because it does not have a type annotation?

The error "this implicitly has type any" occurs when we use the this keyword outside of classes or in functions where the type of this cannot be inferred. To solve the error, add a type for the this keyword as the first parameter in the function.

What is error TS7006?

associated with different solutions. Some of them might make some sense, such as this: Typescript: TS7006: Parameter 'xxx' implicitly has an 'any' type, suggesting that. "In your tsconfig. json file set the parameter "noImplicitAny": false under compilerOptions to get rid of this error."

Is Declared but its value is never read?

To solve 'is declared but its value is never read' error in TypeScript, prefix any unused parameter name with an underscore, or disable the noUnusedLocals and noUnusedParameters options in your tsconfig. json file to silence the error in your entire project.


2 Answers

First, to make typescript tolerate parameters without declaring their type, edit the tsconfig.json

// disable this rule: // "strict": true,  // enable this rule: "noImplicitAny": false 

Second, install the tslint npm package as a prerequisite for the tslint vs code extension

npm install -g tslint 

Third, install the tslint vs code extension

like image 158
Ronin Avatar answered Oct 16 '22 02:10

Ronin


Specify the type: (callback:any) => { } for example.

like image 26
LLL Avatar answered Oct 16 '22 00:10

LLL