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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With