Typescript: what exactly is of type "{[name: string]: string}" to?

Recently, I studied the TypeScript source code and came across a property printed as follows:

private _properties: {[name:string]: string};

I asked myself what this type refers to? What it is?

I thought it would be an object where the key and value should be string.

But I tried it on a TypeScript playground and saw something like

this._properties['name'] = 5;

. So what is the full explanation of this type?

+4
source share
1 answer

No, you are right the first time. _properties is a map from stringto string.

Here is an example on a TypeScript Playground showing the expected error.

, , , .

+4

Source: https://habr.com/ru/post/1540673/


All Articles