Skip to content

Quick fix: "Implement inherited abstract class" should add override keyword to methodsΒ #50464

@KilianB

Description

@KilianB

Suggestion

πŸ” Search Terms

quick fix, code action, override

βœ… 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

When selecting the quick fix action Implement inherited abstract class the generated method signatures should include the override keyword which has been present since version 4.3.

class AdyenPaymentProvider extends LoggingPaymentProvider {
  protected override claimBalance(paymentReference: string, userId?: number | undefined): boolean {
    throw new Error('Method not implemented.');
  }
}

instead of

class AdyenPaymentProvider extends LoggingPaymentProvider {
  protected claimBalance(paymentReference: string, userId?: number | undefined): boolean {
    throw new Error('Method not implemented.');
  }
}

πŸ“ƒ Motivating Example

The autogenerated @Override annotation in Eclipse/java has helped me catch many subtle bug which would have otherwise taken a long time to track down. No harm is done adding the keyword automatically as it will promote the usage of said keyword to a wider audience which will result in better quality code down the line.

In conjunction with changes like #8306 typescript's OOP would simply be less error prone due to stricter enforcements down the line.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions