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
{{ message }}
Repository navigation
Distribute property type union members to create union of object types #36969
Expected behavior:
No error. I'm not exactly sure if this is a bug or feature request but, essentially, it'd be nice if TS could recognize that: { b: [true, "b"] | [false, "a"]; } is identical to { b: [true, "b"] } | { b: [false, "a"]; }
Actual behavior:
Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type 'Test'.
Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type '{ b: [true, "b"]; }'.
Types of property 'b' are incompatible.
Type '[true, "b"] | [false, "a"]' is not assignable to type '[true, "b"]'.
Type '[false, "a"]' is not assignable to type '[true, "b"]'.
Type 'false' is not assignable to type 'true'.
We have some logic that Ron Buckton (@rbuckton) added that handles some of these cases - maybe it's not exactly detecting the narrowing correctly? I would have expected this to work
Activity
RyanCavanaugh commentedon Feb 24, 2020
We have some logic that Ron Buckton (@rbuckton) added that handles some of these cases - maybe it's not exactly detecting the narrowing correctly? I would have expected this to work
rbuckton commentedon Feb 24, 2020
We only currently handle this for cases where the source type is a discriminated union, which isn't the case here.
ethanresnick commentedon Sep 24, 2025
Ryan Cavanaugh (@RyanCavanaugh) Ron Buckton (@rbuckton) FYI, this seems to have been fixed around TS 5.4, so I'm closing this out. I'm assuming that whatever fixed it also came with appropriate regression tests.Edit: I lied; this has not been fixed. Something weird was just happening with my TS playground that made me think otherwise.