microsoft / microsoft/TypeScript
Allow class inheritance in ambient contexts, even with a base private constructor
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
TypeScript Version: nightly (2.5.0-dev.20170902)
Code
declare namespace Foo {
class Bar {
private constructor();
Box: string;
}
class Baz extends Bar {
private constructor();
}
function generator(): Baz;
}
let x = Foo.generator();
x.Box = 'abcd';
Expected behavior:
Compile without error.
Actual behavior:
error TS2675: Cannot extend a class 'Foo.Bar'. Class constructor is marked as private.
Use case
This would allow declaring the types of host-supplied objects, with the following features:
- can inherit members from each other
- cannot be inherited from using standard Typescript/Javascript classes
- cannot be assigned to from an object literal with matching members
- cannot be constructed, only returned from a factory method
declare namespace com.sun.star.text {
class XTextTablesSupplier {
private constructor();
private typekey: XTextTablesSupplier;
readonly TextTables: any;
}
class GenericTextDocument extends XTextTablesSupplier {
private constructor();
private typekey1: GenericTextDocument;
CharacterCount: number;
}
}
declare function createInstance(typename: 'com.sun.star.text.GenericTextDocument'): com.sun.star.text.GenericTextDocument;
let x = createInstance('com.sun.star.text.GenericTextDocument'); // OK
x = new com.sun.star.text.GenericTextDocument(); // Error
let y = x.TextTables; // OK
// The following would be an error
x = {
TextTables: '',
CharacterCount: 5
};
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, das Ambient-Namespace-Beispiel aus dem Issue mit dem referenzierten nächtlichen TypeScript-Verhalten zu kompilieren. Verfolge die Checker-Diagnose für die Erweiterung von Foo.Bar und vergleiche sie mit der erwarteten Akzeptanz der Deklaration. Als erledigt gilt die Aufgabe, wenn das Beispiel kompiliert, während Konstruktion und Objektliteral-Zuweisung weiterhin Fehler bleiben.
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
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100