-
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
Literal type initialization with inheritance #10484
Comments
We tried this a while back, but failed to find a good solution. #6118 gives the result of that work. Proposals are welcome to fix this problem. |
@sandersn I read your comment about RWC. It seems the main issue is lack of variance contract for members of classes. Typing a property with a narrower type in a derived class is OK if your code only reads from the base class but possibly broken if you also write. And there is no way to know this. In a greenfield there are easy way to fix this, but of course they break existing code 👎 . Only thing that comes to mind is a compiler flag 😦
Some of those are so frequent that I would love even a partial fix, e.g. the empty array initializer and implicitely typed lambdas. Those should be doable with backward compatibility, I think? |
At this point we're starting to consider patchwork fixes instead of a general fix. @DanielRosenwasser and I were going to get together soon to brainstorm some way to make partial fixes easy to explain if not completely consistent. In order of likelihood, this is what I'm thinking we would be able to solve:
Unfortunately, the deeper you go on the list, the more of a random bag of patches it becomes. I'm not sure of a solution for that either. |
@sandersn It is a good list! |
TypeScript Version: nightly (2.1.0-dev.20160822)
Code
Expected behavior: Should compile without error. Code seems intuitive to me.
Actual behavior: error TS2415: Class 'B' incorrectly extends base class. Type 'string' is not assignable to type '"a" | "b"'.
The text was updated successfully, but these errors were encountered: