-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inference doesn't find common base type for union with null or undefined - TypeScript 4.8 regression #49938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also reported in Bloomberg feedback #49835 |
This also bisects to #49119. |
Also interestingly, if you write I'm a little confused as to why the argument order matters here, but given that the inference if you swap the arguments is the same in 4.7, it's nothing new. |
I pinned this down to this part of the PR: https://github.com/microsoft/TypeScript/pull/49119/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R21147 This part of the code doesn't consider the fact that any of the types could be unions that contain |
My fix doesn't seem to be the right one; we should probably discuss the intended inference behavior here. EDIT: Well, maybe it is, after fixing a few things: Playground Link |
Fixed by #50021. |
Bug Report
π Search Terms
inference common base type null undefined
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
In 4.8 TypeScript can't find common base type between
B
andundefined | D
. In 4.7 this used to beB | undefined
.This also happens for literal types and their respective base types as well as for arrays as shown in the 'Other Examples' in the playground link. I didn't include the code as the bug is the same, it's just different instances we found in our code.
π Expected behavior
Typescript finds the type
B | undefined
forT
as it did in 4.7.The text was updated successfully, but these errors were encountered: