-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Union types are not expanded properly when checking if type satisfies generic constraint #49778
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
If it's indeed a bug, a temporary workaround could be something like let d: MyType<NotUnionType extends UnionType ? NotUnionType : never> The |
This looks like two bugs, actually:
edit: I stand corrected on point 2. See Ryan's comment immediately below. |
Changing error arity based on the order of lines is definitely a bug, though. |
In that case, repro: type AObjOrBObj = { name: "A" } | { name: "B" };
type AOrBObj = { name: "A" | "B" };
type Generic<T extends AObjOrBObj> = T;
type T = Generic<AOrBObj>; // error if here
declare let x: AObjOrBObj;
declare let y: AOrBObj;
x = y; // ok
y = x; // also ok
//type T = Generic<AOrBObj>; // not an error if here |
I was hoping this would be fixed by #49718 (because if you have |
It turns out that it was in fact fixed by #49718; not sure how I managed to make it fail in my comment above. Will send a PR which adds a test. |
Bug Report
π Search Terms
Union types expansion, generic constraints
π Version & Regression Information
4.6, works fine in 4.5
β― Playground Link
Playground link with relevant code
π» Code
The error doesn't reproduce, however, if I change the order of lines:
π Actual behavior
Error when instanciating
MyType<NotUnionType>
π Expected behavior
No error. Also error trace seems to be missing some entries in the beginning (I would expect it to start with something like
NotUnionType does not satisfy the constraint UnionType
whereas in actuality is starts withType 'NotUnionType' is not assignable to type '{ name: "B"; }'
).The text was updated successfully, but these errors were encountered: