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
typeA={a: number,b: string};consta: A={a: 1,b: 'foo'};constb: A={ ...a,b: 123};// doesn't type check, b should be string (correct)constpropB: 'b'='b';constc: 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.
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.4.2
Code
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 theb
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.
The text was updated successfully, but these errors were encountered: