Closed
Description
openedon Aug 28, 2014
interface Dictionary {
[key: string]: any;
}
var dict: Dictionary = {};
dict['work']; // Works
dict.work; // Doesn't work
Resulting JavaScript is valid but TypeScript blocks this.
Allowing this would allow general JavaScript dictionary use cases.
Example: from MDN. el.dataset.id
is generally preferred to el.dataset['id']
.
<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe
</div>
var el = document.querySelector('#user');
// el.id == 'user'
// el.dataset.id === '1234567890'
// el.dataset.user === 'johndoe'
// el.dataset.dateOfBirth === ''
el.dataset.dateOfBirth = '1960-10-03'; // set the DOB.
// 'someDataAttr' in el.dataset === false
el.dataset.someDataAttr = 'mydata';
// 'someDataAttr' in el.dataset === true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment