-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 2.4.2
Code
type A = { a: number, b: string };
const a: A = { a: 1, b: 'foo' };
const b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct)
const propB: 'b' = 'b';
const c: A = { ...a, [propB]: 123 }; // type checks even though i'm setting b to a number (incorrect)
Expected behavior:
Last statement should be invalid, since propB
is of type 'b'
, which should be enough information for TS to know that i'm setting the b
property.
Actual behavior:
Last statement is valid for TS. This also happens for union types of string or number literals. When the types for the values in those keys are the same, and attempting to set a value using a computed property, TS allows invalid values.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created