-
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
Ternary two different types infers to one type when one is a subset of the other #46449
Comments
This is normal subtype reduction and is by design, as far as I know. |
To be fair there is a downside to this kind of subtype reduction: |
Yeah, I’ve seen a couple cases like this where subtype reduction is a little unfortunate. Don’t think there’s anything to be done though. |
to @fatcerberus, how is this done then? it doesn't even seem to work when I explicitly say that |
@danielbartsch In that example the variable If you want to explicitly type it as const ab: A | B = (Math.random() > 0.5 ? a : b) as A | B |
Well, it would be |
Thank you very much! |
Bug Report
🔎 Search Terms
ternary type union
Maybe related: #33070, #20863
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
ab
infers toB
🙂 Expected behavior
ab
should infer toA | B
The text was updated successfully, but these errors were encountered: