You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// type error, as expectedconstfoo1={Key1: 1,Key1: 2}// ok, let's try with computed propertiesconstKey1='Key1'constKey2='Key2'// no type error? widened type to `string`, maybe?constfoo2={[Key1]: 1,[Key1]: 2}// type error when literals are usedconstfoo3={['Key1']: 1,['Key1']: 2}// now, let's try with enumsenumTestEnum{Key1='Key1',Key2='Key2'}// no type error? widened type to `string`, maybe?constfoo4={[TestEnum.Key1]: 1,[TestEnum.Key1]: 2}
Expected behavior:
I found some weirdness around how typescript treats computed properties & duplicate keys. I would expect it to detect duplicate keys when passed variables with specific type literals, whether created via constants or enum members.
Actual behavior:
Duplicate keys are not detected when variables are used as computed properties. This is particularly a problem when trying to use enum members, because there is no alternative way to use them as keys in an object.
TypeScript Version:
3.3.0-dev.201xxxxx
Search Terms:
computed properties
,duplicate keys
Code
Expected behavior:
I found some weirdness around how typescript treats computed properties & duplicate keys. I would expect it to detect duplicate keys when passed variables with specific type literals, whether created via constants or enum members.
Actual behavior:
Duplicate keys are not detected when variables are used as computed properties. This is particularly a problem when trying to use enum members, because there is no alternative way to use them as keys in an object.
Playground Link:
https://bit.ly/2TrDznF
Related Issues:
Possibly these:
#26208
#18596
The text was updated successfully, but these errors were encountered: