Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: TS7006: Parameter 'xxx' implicitly has an 'any' type

Tags:

typescript

People also ask

How do you fix parameter implicitly has an any type?

The "Parameter 'X' implicitly has an 'any' type" error occurs when a function's parameter has an implicit type of any . To solve the error, explicitly set the parameter's type to any , use a more specific type, or set noImplicitAny to false in tsconfig.

Has an any type TypeScript?

To fix the "parameter implicitly has an 'any' type" error in TypeScript, we can set the noImplicitAny option to false in tsconfig. json . to set the noImplicitAny option to false in tsconfig. json.


You are using the --noImplicitAny and TypeScript doesn't know about the type of the Users object. In this case, you need to explicitly define the user type.

Change this line:

let user = Users.find(user => user.id === query);

to this:

let user = Users.find((user: any) => user.id === query); 
// use "any" or some other interface to type this argument

Or define the type of your Users object:

//...
interface User {
    id: number;
    name: string;
    aliases: string[];
    occupation: string;
    gender: string;
    height: {ft: number; in: number;}
    hair: string;
    eyes: string;
    powers: string[]
}
//...
const Users = <User[]>require('../data');
//...

In your tsconfig.json file set the parameter "noImplicitAny": false under compilerOptions to get rid of this error.


if you get an error as Parameter 'element' implicitly has an 'any' type.Vetur(7006) in vueJs

with the error:

 exportColumns.forEach(element=> {
      if (element.command !== undefined) {
        let d = element.command.findIndex(x => x.name === "destroy");

you can fixed it by defining thoes variables as any as follow.

corrected code:

exportColumns.forEach((element: any) => {
      if (element.command !== undefined) {
        let d = element.command.findIndex((x: any) => x.name === "destroy");

I found this issue in Angular to arguments of function.

Before my code giving error

Parameter 'event' implicitly has an 'any' type

Here Is code

changeInpValue(event)
{
    this.inp = event.target.value;
}

Here is the change, after the argument write : any and the error is solved

changeInpValue(event : any)
{
    this.inp = event.target.value;
}

Working fine for me.