-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Intersection types with duplicated properties of different types #4275
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
But some could read this as the resulting type is: interface C {
p: number|string;
} I am not sure of the rules of the intersection types in 1.6 though, but I think there has been a lot of discussion lately that they are more "merge-like" types then strictly "intersection" types, but I believe they are intended to be quite permissive. |
ok @kitsonk , It works well the way it is, my suggestion it's only for better error message. However |
We recognize that intersections between primitives are hard to rationalize, but it's not obvious where or why we would actually issue an error. Consider some code: // Can't error here
function merge<T, U>(x: T, y: U): T & U {
return null; // TODO
}
// Maybe error here?
let y = merge({p: ''}, {p: 32});
// Or here?
let z = y.p; If we think about some 'bigger' types: interface A {
x: number;
y: string;
}
interface B {
x: string;
z: boolean;
}
type C = A & B; Is |
Thank you @RyanCavanaugh , I understood the point. It's not problem to me, typescript compiler already issues the error on assignment, it's enough. |
The text was updated successfully, but these errors were encountered: