-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Previous generic union does not narrow to an union again with type predicate #38869
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
This is the same as #31156; the problem is that the left constituent of the union |
Thank you @jack-williams, I didn't find that issue, reading it now. However the PR that should close that issue is closed with the comment "[...] there’s not currently a solution that’s worth the disruption it will bring". Something similar in #32158. Also there is something I don't understand completely here. I updated the description just in case. Consider this snippet: // CASE 4: narrowing `A<any, any> | B` (does not work)
declare function onlyASomeHere(x: A<Some, keyof Some>): void;
declare const a: A<any, any>;
// `A<any, any>` is assignable to `A<Some, keyof Some>`
onlyASomeHere(a);
declare const some3: A<any, any> | B;
assertIsX(some3);
// ERROR: `some3` narrowed to `B`, not `X<Some>`
some3.t ? some3.v : some3.e; The first lines show that If this is still related to the issue you have linked, feel free to close this as a duplicate and I'll subscribe to that instead. |
Assignability and subtyping are different relations, so while Function calls use assignability, which is why there is no error. |
Oh, I see. Thank you for your explanation. Feel free to close this as a duplicate then :) |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 4.0.0-dev.20200531
Search Terms: type narrow discriminant generic
Code
I'm using a type assertion, but a type predicate makes no difference. The same happens starting with
X<any>
orX<unknown>
.Expected behavior:
some2
is narrowed to the unionA<Some> | B
so.v
can be accessed whent === true
.Actual behavior:
some2
narrows only toB
, so whent === true
some2
isnever
.Playground Link: playground
Related Issues: Maybe #30557 but that case works on last nightly and this does not.
The text was updated successfully, but these errors were encountered: