close

[Solved] TypeScript TS7015: Element implicitly has an ‘any’ type because index expression is not of type ‘number’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeScript TS7015: Element implicitly has an ‘any’ type because index expression is not of type ‘number’ in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeScript TS7015: Element implicitly has an ‘any’ type because index expression is not of type ‘number’ Error Occurs?

Today I get the following error TypeScript TS7015: Element implicitly has an ‘any’ type because index expression is not of type ‘number’ in javascript.

How To Solve TypeScript TS7015: Element implicitly has an ‘any’ type because index expression is not of type ‘number’ Error ?

  1. How To Solve TypeScript TS7015: Element implicitly has an 'any' type because index expression is not of type 'number' Error ?

    To Solve TypeScript TS7015: Element implicitly has an 'any' type because index expression is not of type 'number' Error

  2. TypeScript TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'

Solution 1

I used this to get around it so I could use the window object.

//in js code somewhere
window.DataManager = "My Data Manager";


//in strict typescript file
let test = (window as { [key: string]: any })["DataManager"] as string;
console.log(test); //output= My Data Manager

Solution 2

In tsconfig.json

 compilerOptions:{

  "suppressImplicitAnyIndexErrors": true,
  "strictNullChecks":false,
  "strictPropertyInitialization": false,

 }

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment