Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: What exactly refers the type "{[name:string]: string}" to?

Tags:

typescript

I looked into some TypeScript source code lately and came across a property typed like this:

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

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

I thought it would be an object where key and value need to be string.

But I tried it in the TypeScript Playground and saw that something like

this._properties['name'] = 5;

is also valid. So what's the complete explanation of this type?

like image 981
Johannes Klauß Avatar asked May 15 '14 10:05

Johannes Klauß


1 Answers

No you're right the first time. _properties is a map of string to string.

Here's an example on the TypeScript Playground demonstrating the expected error.

If you can link an example where that statement is valid we can figure out why.

like image 109
Jeffery Grajkowski Avatar answered Oct 14 '22 12:10

Jeffery Grajkowski