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.

New flag `--noImplicitAbstractOverride` which mandates the use of `override` when implementing an abstract method

See original GitHub issue


🔍 Search Terms

flag override implicit noImplicitOverride abstract

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

⭐ Suggestion

Currently, when --noImplicitOverride is enabled, overriding (or implementing) an abstract method does not require the use of keyword override.

I suggest adding a new flag --noImplicitAbstractOverride, which, when enabled in conjunction with --noImplicitOverride, will also require override when implementing an abstract method.

📃 Motivating Example

In issue #44457, @RyanCavanaugh explained the rationale behind --noImplicitOverride not covering implementing abstract methods is that --noImplicitOverride is designed to prevent typos. Since not implementing an abstract method will already result in an error, it is not necessary to let --noImplicitOverride also cover that case.

However, that is only one use case for the override keyword. In fact, I don’t think --noImplicitOverride has ever helped me catch any typo bugs that way, thanks to the modern IDE I use, which automatically fills in method names when I am about to override a method. (I am not saying it is not helpful, though.)

In my opinion, one of the most valuable functionality that override provides is explicitly telling the programmers which methods are from the the super class and which methods are new. This is especially valuable when reading code of a class in a complicated inheritance tree.

Ideally, I think such behavior should be a part of --noImplicitOverride. However, since that ship has already sailed, it seems a new flag is required.

Side note: I do realize that implementing an abstract method is technically not really overriding anything. However, by this line of reasoning, when implementing abstract methods override should be completely disallowed instead of optional.

(Hey, the person giving me thumbs down, it will be better if you can come out and explain why you don’t agree with me.)


Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:28
  • Comments:5

github_iconTop GitHub Comments

diesal11commented, Jan 5, 2022

I found myself here after having enabled --noImplicitOverride thinking this would be the default behaviour. Would love to see this implemented in future.

frank-weindelcommented, Sep 3, 2022

I agree with this. I think the override keyword more than anything else helps inform developers that a method and its signature are specified in the base class and hence its implementation may have some influence on the class that is not readily apparent by just looking at the sub-class implementation. While override may not be actually what you’re doing in an abstract class, I still think its relatively intuitive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overriding abstract Methods
An abstract class usually contains abstract methods. An abstract method definition consists of: optional access modifier ( public, private, and others), ...
Read more >
Use override when implementing abstract members
Since fool has a default implementation, this is valid but does not behave the way we think. Had we used the override keyword,...
Read more >
Why is it required to have override keyword in front of abstract ...
When we create a class that inherits from an abstract class and when we implement the inherited abstract class why do we have...
Read more >
Using an Interface vs. Abstract Class in Java - Baeldung
i.e., we cannot use the statement new TypeName() directly to instantiate an object. If we used the aforementioned statement, we have to override...
Read more >
Abstract Class in Java | DigitalOcean
An abstract class is mostly used to provide a base for subclasses to extend and implement the abstract methods and override or use...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found