-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inconsistent subtyping between union of objects and object with union property when the number of variants > 25 #51677
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
See e.g. #43283. It's an intentional tradeoff for performance reasons because this comparison involves a potentially combinatorially explosive expansion in the general case. |
@fatcerberus Thank you. Is this behavior documented somewhere? |
The GitHub issues are considered to be part of the documentation. Beyond that, I suspect itβs not documented because itβs considered a design limitation (i.e. subject to removal or relaxation if a way to do so without hurting performance is found) and the mechanism itself is a bit tricky to explain: the limit of 25 types applies to the number of types in the expansion, so for example As for why it works when |
Thank you for the detailed explanation. I understood. |
Bug Report
π Search Terms
object union subtyping
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
The exact same code with that of playground above.
π Actual behavior
Type
{x: T1 | ... | TN}
is not treated as a subtype of{x: T1} | ... | {x: TN}
when N > 25π Expected behavior
It should be treated as a subtype. Or at least, the behavior should not change between N <= 25 and N > 25
The text was updated successfully, but these errors were encountered: