find and solve || findandsolve.com
Please wait.....

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


Answer



Option 1.


First, you  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


Option 2.


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



Option 3.


 getSomeValue() {

    this.commonService.getSomeValue().subscribe(
        (response: { data: any; }) => {
        this.groupList = response.data;
        //console.log(response);
      }, (error: any) => {
        console.log(error);
      }
    )
  }


or

  getList() {

    return this.http.get<any>(this.appUrl + "api/GetList").pipe(
      retry(4),
      map(data => {
        return data;
      },function(error: string) {
              console.log("List Service Error " + error);
          })
    );
  }



Option 4.


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

Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response