-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Inference for contravariant positions in second argument of conditional type results in arbitrary union supertype #38039
Comments
Intersections of functions behave like overloaded functions, and the behaviour for a conditional type inferring from an overloaded function is to use the last signature as described in #21496
|
I would expect that if I used conditional on an intersection
types of arguments would be inferred either as
or
or
but surely not
that we're getting right now. |
Re: the title, it would be plainly wrong to do this type Pt = { x: number } & { y: number }
type IsPoint<T> = T extends { x: number, y: number } ? true : false;
// Expected true, not false & false
type X = IsPoint<Pt>; |
I'm not sure how to properly call it otherwise. The "distributive conditional types" term doesn't really cover that distributivity through contravariant positions converts unions to intersections (and in case of this issue, vice versa). The example you've shown doesn't show distribution through contravariant positions. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.8.3 (Nightly is broken at the moment)
Search Terms:
distributive conditional types over intersection
Code
Expected behavior:
XY
andAB
bothtrue
, i.e. condition types distribute over intersections the same way as over unions.Actual behavior:
XY
isfalse
. Type checker picks the last term of intersection.Playground Link:
Playground Link.
Related Issues:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types
The text was updated successfully, but these errors were encountered: