-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript
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
joshjg, nth-commit, carlpaten, SancheZz, niekert and 6 more
Metadata
Metadata
Assignees
Labels
Experimentation NeededSomeone needs to try this out to see what happensSomeone needs to try this out to see what happensSuggestionAn idea for TypeScriptAn idea for TypeScript