Abstract classes that implement interfaces shouldn't require method signatures
See original GitHub issueTypeScript Version: 2.7
Search Terms: abstract class implements interface
Code
interface FooFace {
foo();
}
abstract class FooClass implements FooFace {
// ^^^^^^^^
// Class 'FooClass' incorrectly implements interface 'FooFace'.
// Property 'foo' is missing in type 'FooClass'.
//
// unless the following is uncommented:
//abstract foo();
}
// contrast:
abstract class BarClass {
abstract bar();
}
abstract class BarSubClass extends BarClass {
// no `abstract bar();` required
}
Expected behavior: Abstract classes that implement interfaces don’t need to define abstract type definitions to satisfy interface.
Actual behavior: They do.
Related Issues:
- #19847, where typescript fails to see that a superclass does implement a method (contrast this ticket, where typescript fails to see that a class need not implement a method)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:67
- Comments:33 (11 by maintainers)
Top Results From Across the Web
java - What (not) to declare when implementing an interface ...
Turn abstract class B into an AUtil class that doesn't implement A. The method signatures may require an additional argument of type A...
Read more >Abstract Classes, Part 2 – Abstract Classes and Interfaces
When other methods need to have their implementation of a method, then you simply provide the method signature and mark it as abstract....
Read more >Easiest explanation of Abstract class and Interface - Medium
but for Interfaces, all the methods are now just signature. The class StoneCold implements Wrestler interface and define all three abstract ...
Read more >Why shouldn't I use an Abstract Class instead of an Interface ...
Interfaces do not provide classes at all, they only provide methods that have to be implemented, an abstract class is a class that...
Read more >Chapter 9. Interfaces - Oracle Help Center
A class may be declared to directly implement one or more interfaces, meaning that any instance of the class implements all the abstract...
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
2 years later…
this seems like an obvious and basic feature for any object-oriented language: how come it hasn’t been implemented ?
Apparently this can be worked-around with class and interface merging:
That seems redundant, though, I still think this should be fixed.
https://github.com/Microsoft/TypeScript/issues/6413#issuecomment-170737032