-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type assertion only works if one type is completely assignable to the other #1447
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
Another potential fix is to copy optional properties into an object literal during contextual typing if they are missing. |
The right solution here is probably a new "is assignable to or from" relation as you suggest. |
Per issue #2441, we can use this for equality comparisons too. |
I don't think we should fix this issue. I think the fix is too costly and complex, and I don't think the issue is serious enough to warrant it. @mhegazy @ahejlsberg Do you agree? |
I agree, I think we can close this one. |
This happens because with respect to property
a
, Foo is the winner, but with respect to propertyb
, the object literal is the winner (because b is missing). I think what the user expects is for us to mix and match the direction of assignability at all levels of nesting. So if each property is assignable in either direction, the check passes for that property. If the check passes for all the properties, the type assertion is allowed.This would require work in the spec to add a new symmetric relation "is assignable to or from", which applies itself appropriately to nested types and other nested constructs.
The text was updated successfully, but these errors were encountered: