TS7017

error TS7017: Element implicitly has an ‘any‘ type because type ‘{}‘ has no index signature.

Broken Code ❌

1
const recipients = {};

Fixed Code ✔️

You have to define the type for indexing your object properties (object["index"]):

1
const recipients: {[index: string]: number} = {};

The name of the index can be freely chosen:

1
const recipients: {[myKey: string]: number} = {};

How to fix such errors in interfaces:

1
2
3
interface Recipients {
[index: string]: number;
}

Alternative, but not recommend:

error TS7017: Element implicitly has an ‘any‘ type because type ‘typeof globalThis‘ has no index signature.

Broken Code ❌

1
global.client = new APIClient(APIClient.URL_DEMO, 'global-demo-api-key');

Fixed Code ✔️

1
2
3
4
5
declare global {
var client: APIClient;
}

global.client = new APIClient(APIClient.URL_DEMO, 'global-demo-api-key');

Reference:

Video Tutorial