-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Union of a nullable and not nullable setter results wrongly into a nullable setter #50142
Comments
Related: #45376 |
Properties are always measured covariantly, and this is unsound under supertype aliasing. |
I'm kind of surprised this isn't caught under the rules of #30769. Even |
I am not sure if I understand this completely. If this is unsound, I cannot follow why it should be the expected behavior. If there is somewhere a more detailed reading about the reasoning, I would be glad to get a pointing. |
For the same reason that |
Thank you for the explanation. I can follow the reasoning. Though, concerning the backwards compatibility: Typescript has introduced many optional "strict" flags to solve this problem. |
N |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
setter, union, wrong type
π Version & Regression Information
4.7.4
Also checked 3.9.7 with same results.
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAEByCuJwCMQFNoG8BQBIADvKgJbDQRoAu0AZgPZ0AUA+gHZoDuAamCPBgC5oreAFtkaAE7QAPsMQgAlNCx4Avtg3ZQkGLDqUESMKgw4CREKXJVaDFu269+0ISPFTlq3Bq3A6rBDUIsam0AC8wpxwCibojIoA3NoBQcIGRijoEVEccBmxpgnJ2AD0pdD+kpJowJQgAJ4ANNAcGMBgrKwG0LrEAOas0ABEISDD0JR0I92GhejD2GNxaAB09NORY8mzmSvrDDnb0OXQACoAFsQw15V01bX1Db13ovjE2VKS96vYZRUAdQuaCG8AgxFY-Re8FYxAC0DoNGgyAMF0mDXwaBgAElWnREAATXpQMQYSgXMDUBr48iUD4gSqdWbE8GDGYKCYSDpgtD-SbA6AwuFDCkwKa0BQ0en89qpSiSMAQmCI5Go9GYiCraAAIXglBawJq0Gp8EZQz6bNGHN+NBhdWFNkkADdSGgALJUC50AmMMCuGKhbJyfRzQNoZRCJ10YhE8xgA6beRIRInCqXW63Zl+-xvD4YL73FrIPXQXHkiEAa2gxGoEC9hORa00QA
π» Code
π Actual behavior
When using a union of two types with a setter where one is nullable and another one is not, the resulting setter is also nullable.
π Expected behavior
I believe this is wrong, as the union must ensure that the constraints of both types are fulfilled. Which mean that
null
should be prohibited as one of the types does not allow it.The text was updated successfully, but these errors were encountered: