Closed
Description
TypeScript Version: 3.1.0-dev.20180809
Search Terms: dynamic key duplicate identifier
Code
const X = 'x'
enum Y {
ONE = 'one',
TWO = 'one'
}
// static key - 'duplicate identifier' error
const obj1 = {
'y': 'wham',
'y': 'bam' // as expected, tsc error `Duplicate identifier ''y''`
}
const obj2 = {
y: 'wham',
y: 'bam' // as expected, tsc error `Duplicate identifier 'y'`
}
// [the bug] dynamic key - no 'duplicate identifier' error
const obj3 = {
[X]: 'wham',
[X]: 'bam' // no tsc error!
}
const obj4 = {
[Y.ONE]: 'wham',
[Y.TWO]: 'bam' // no tsc error!
}
Expected behavior:
When assigning duplicate dynamic keys to plain objects, which can be statically inferred (e.g. enum
s or const
with primitive type) - tsc should show a compilation error.
Actual behavior:
no compilation error.
Playground Link:
a long long long playground link ...
Related Issues: N/A