question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abstract classes that implement interfaces shouldn't require method signatures

See original GitHub issue

TypeScript 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.

Playground Link

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:open
  • Created 5 years ago
  • Reactions:67
  • Comments:33 (11 by maintainers)

github_iconTop GitHub Comments

19reactions
syffscommented, Mar 30, 2020

2 years later…

this seems like an obvious and basic feature for any object-oriented language: how come it hasn’t been implemented ?

16reactions
laughinghancommented, Mar 23, 2018

Apparently this can be worked-around with class and interface merging:

interface FooFace {
    foo();
}
abstract class FooClass implements FooFace {}
interface FooClass extends FooFace {}

let x: FooClass;
x.foo(); // no error

That seems redundant, though, I still think this should be fixed.

https://github.com/Microsoft/TypeScript/issues/6413#issuecomment-170737032

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found