microsoft / microsoft/TypeScript

Add a code action to implement (overwritten) method from base class

Offen
#31,787 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

implement, inherited, method

Suggestion

When implementing a method that is defined in a class's base class or in external type declarations, it would be helpful if we didn't have to type out the method signature that is already known to TypeScript.

Use Cases

Overwriting methods in inherited classes. Here's an example for implementing a custom winston transport.
grafik
TypeScript knows the method signature, but I have to type it out manually, potentially making a mistake along the way.

Examples

import * as Transport from "winston-transport";

export class SpyTransport extends Transport {
	log| // cursor here!
}

VSCode should offer a code action implement method "log" from base class "Transport". After invoking it, the code should look like this:

import * as Transport from "winston-transport";

export class SpyTransport extends Transport {
	public log(info: any, next: () => void): any {
		throw new Error("not implemented!");
	}
}

For reference, the type declarations look as follows:

declare class TransportStream extends stream.Writable {
  public format?: logform.Format;
  public level?: string;
  public silent?: boolean;
  public handleExceptions?: boolean;

  constructor(opts?: TransportStream.TransportStreamOptions);

  public log?(info: any, next: () => void): any;
  public logv?(info: any, next: () => void): any;
  public close?(): void;
}

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den TypeScript- oder VSCode-Einstiegspunkt für code action zu finden, der geerbte oder nicht implementierte Methoden verarbeitet. Verwende das TransportStream-Beispiel und die Deklaration des Issues als Verhaltensreferenz; betrachte die Arbeit als abgeschlossen, wenn eine code action die geerbte Methode anbietet und ihre bekannte Signatur sowie einen Stub generiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
developer-experience
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.