TS7015

Element implicitly has an 'any' type because index expression is not of type 'number'.

Broken Code ❌

const users = ['Anna', 'Benny', 'Clara'];
 
function returnUser(id: string | number) {
  return users[id];
}

This error occurs because TypeScript cannot guarantee that the index expression (id) is a valid key of the user object, and it infers the return type as any.

Fixed Code ✔️

Arrays can be accessed with numerical indices, thus you can use type number:

const users = ['Anna', 'Benny', 'Clara'];
 
function returnUser(id: number) {
  return users[id];
}