microsoft / microsoft/TypeScript
Improve feedback for abstract class instantiation error messages
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
SUGGESTION
Recently, I was trying to use a library written in ES2015 in an Ionic 2 project, and kept getting a Cannot instantiate abstract class 'Foo'. Foo is a concrete class that extends abstract class Bar, which extends abstract class Baz. The problem turned out to be a typo in Bar.d.ts (see below), which (I believe) made Typescript think that Foo did not implement some abstract methods of Bar and/or Baz (I'm still not sure which), but it took me a day and half to figure out what was going on. This error message should have more information about why Foo is abstract: Foo is declared as abstract or Foo does not implement abstract methods ...
TypeScript Version: 2.0.9
Code
Baz.d.ts
export as namespace Baz;
declare abstract class Baz {
abstract baz(): string;
}
Bar.d.ts
export as namespace BarTypo;
declare abstract class Bar extends Baz {
abstract foo(): void;
abstract bar(): string;
baz(): string;
}
export { Bar };
Foo.d.ts
import { Bar } from './bar.d';
export as namespace Foo;
declare class Foo extends Bar {
constructor(opts?);
foo(): void;
bar(a: string): string;
}
export { Foo };
otherProject.ts
import { Foo } from 'library';
export class Service {
foo: Foo;
constructor() {
this.foo = new Foo({ opt: true });
}
}
Expected behavior:
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): baz.
OR
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): foo, bar.
OR
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): baz (from Baz); foo, bar (from Bar).
Actual behavior:
Error: Cannot instantiate abstract class 'Foo'.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Diagnose mit Baz.d.ts, Bar.d.ts, Foo.d.ts und otherProject.ts unter Verwendung des hier beschriebenen Verhaltens von TypeScript 2.0.9 zu reproduzieren. Verfolge den Fehler des Compilers bei der Instanziierung einer abstrakten Klasse und sorge dafür, dass die Meldung die relevanten fehlenden abstrakten Methoden oder die relevante Deklaration nennt. Als abgeschlossen gilt dies, wenn das Beispiel meldet, warum Foo nicht instanziiert werden kann, und einer der vorgeschlagenen erwarteten Meldungen entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100