-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Type Merging between extends and intersection #8606
Copy link
Copy link
Open
Labels
Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Metadata
Metadata
Assignees
Labels
Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Type
Fields
Give feedbackNo fields configured for issues without a type.
TypeScript Version:
1.8.10
Code
Expected behavior:
That
FooBarAwould work instead of throwing an error.Actual behavior:
FooBarAcomplainsInterface '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.