Allow extending multiple interfaces with different, but compatible types
See original GitHub issueinterface Change {
uid: string;
type: string;
}
interface SomeChangeExtension {
type: 'some';
foo: number;
}
interface SomeChange extends Change, SomeChangeExtension { }
In this example, I was expecting SomeChange
to have a type equivalent to:
interface SomeChange {
uid: string;
type: 'some';
foo: number;
}
But it would result in error:
Interface 'SomeChange' cannot simultaneously extend types 'Change' and 'SomeChangeExtension'.
Named property 'type' of types 'Change' and 'SomeChangeExtension' are not identical.
In this case, 'some'
is compatible with string
if the order of interfaces being extended is respected.
The reason why I want this to be allowed is that, I need to maintain multiple interfaces of the same kind of change during different stages: raw change, change, broadcast change. And having to duplicate part of the “extension” on every of them doesn’t look good.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:125
- Comments:29 (10 by maintainers)
Top Results From Across the Web
Extend multiple interfaces in TypeScript | bobbyhadz
TypeScript is telling us we can't extend from an interface and use the same property name with a different, incompatible type.
Read more >Extending object-like types with interfaces in TypeScript
Extending multiple interfaces refers to the concept of composition where the interface is designed to extend attributes it needs.
Read more >Two interfaces with same methods having same signature but ...
The question is: Can a java class implement Two interfaces with same methods having the same signature but different return types??
Read more >An interface extending multiple interfaces - java - Stack Overflow
The best thing to do is try to compile it for yourself and find out. · The two methods have conflicting return types,...
Read more >Handbook - Interfaces - TypeScript
To describe a function type with an interface, we give the interface a call signature. This is like a function declaration with only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mhegazy I was thinking about respect the extensions order, and if the later one is compatible with the former one, then use the later one instead.
E.g.:
In which
ConcreteFooYou
should be equivalent to:@vilic This should help you