microsoft / microsoft/TypeScript
Allow class inheritance in ambient contexts, even with a base private constructor
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
};
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia compilando l’esempio di namespace ambient dell’issue con il comportamento notturno di TypeScript a cui si fa riferimento. Segui la diagnostica del checker per l’estensione di Foo.Bar e confrontala con l’accettazione prevista della dichiarazione. Il lavoro è completato quando l’esempio viene compilato, mentre la costruzione e l’assegnazione di un object literal continuano a produrre errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100