-
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
Sub-typing issue when referencing a parent entity #30582
Comments
It's the opposite, but I know what you mean. |
Actually, it's not quite a duplicate - but it's just that we've made an assumption that mutable properties should be related in a covariant, rather than invariant, manner with respect to their containing types. I don't know if we could realistically fix this. |
Yes sorry, that's what I meant ^^
That's a rare scenario for sure, so this problem shouldn't come in many scripts. I don't know how this is implemented in the compiler, so I let you judge this by yourself :) |
Our type system is covariant by default and writing through a supertype alias is the major hole created by that. It's definitely a trade-off. |
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.4.0-dev.201xxxxx
Expected behavior: Do not compile because
b
shouldn't be able to be a reference toa
. Indeed,B
shouldn't be considered as a sub-type ofA
becausenumber | string
does not strictly overlapsnumber
Actual behavior: Code compiles, and fails at runtime.
Playground Link: https://bit.ly/2U2Cpmz
The text was updated successfully, but these errors were encountered: