Open
Description
TypeScript Version: 4.0.0-dev.20200518
Search Terms: computed property, union
Code
type Key = 'a' | 'b';
const index1: Record<Key, string> = { a: '', b: 0 }; // Errors as expected, ok
const index2: Record<Key, string> = { a: '', b: '' };
const b: Key = 'b';
const index3: Record<Key, string> = { ...index2, [b]: 0 }; // Errors as expected, ok
declare var k: Key;
// No errors, allowing anything to be assigned to string
const index4: Record<Key, string> = { ...index2, [k]: [] };
const index5: Record<Key, string> = { a: '', b: '', [k]: 0 };
Expected behavior:
Expected error for invalid assignments in index4
and index5
.
Actual behavior:
No error, allowing anything to be assigned to string
Playground Link: here
Related Issues:
#36920: perhaps the computed property is deemed an excess property, though I don't think it should be