-
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
Type Merging between extends and intersection #8606
Comments
Proposed fix: When we consider signatures, after flattening the list of all signatures, we should then stable-sort, placing signatures with the more string literal types before those with fewer. |
I am going to try to tackle this. |
I just ran into something similar also.
Actually, I was surprised it even cares to pull in private members to a public interface. |
ping @RyanCavanaugh |
My usecase was this: class MyClass { };
export interface IOptionsBase {
}
export interface IOptions extends IOptionsBase {
myCb?: (this: Window, data: boolean) => void;
}
export interface IOptionsEx extends IOptionsBase {
myCb?: (this: MyClass, data: number) => void;
}
// should get: myCb?: (this: Window|MyClass, data: number) => void;
export interface ICtrlMetaData extends IOptions, IOptionsEx {
} |
TypeScript Version:
1.8.10
Code
Expected behavior:
That
FooBarA
would work instead of throwing an error.Actual behavior:
FooBarA
complainsInterface 'FooBarA' cannot simultaneously extend types 'Foo' and 'Bar'. Named property 'on' of types 'Foo' and 'Bar' are not identical.
While that is true in the strictest sense, the "base" override matches, which means in theory the string literal types could be merged and the error should only occur if there is a conflict between a specific string literal type.
Using the intersection type works perfectly fine and the resulting type mirrors the runtime behaviour. Using the "reimplement all methods" (
FooBarB
) gets really tedious really quickly when you are trying to do something like model event listeners like the above.The text was updated successfully, but these errors were encountered: