-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Weird behavior on Intersection Types #11972
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
The behavior is right, IMO.
|
@lbguilherme this question actually relates to variance. In light of TypeScript's covariant nature your view is entirely correct. It is worth noting that this is because reads of the property or covariant and so are writes. One could imagine that if the language supported contravariance @Brooooooklyn's expectation would be correct. |
I've already reported same in #9239. |
The result of intersecting two types is a new type whose values are the union of the two values of the two constituents. By definition this is a deep operation (i.e. it intersects the types of all properties). Sometimes this result in types with empty value sets, this is not only for properties but for all intersection types, e.g. Primitives are the special case here, but it is useful to describe something that is both If you are looking for is for the type of the second property to "override" the type of the property with the same name,( a la If you want the compiler to verify that the two properties are "sub types", then you should be using the interface bar extends foo{
a: string; // Error `string` is not assignbale to `number`
c: number;
} @iskiselev, #9239 is related but not the same issue. |
Things like these are why I feel intersection types should still be checked for compatibility. That would be the solution here. |
TypeScript Version: 2.0.3
Code
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: