microsoft / microsoft/TypeScript
Generating type definitions for mixin classes with protected members
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 2.4.2
Code:
I'm using mixins as described by: https://github.com/Microsoft/TypeScript/pull/13743
export type Constructor<T> = new(...args: any[]) => T;
export function Unsubscriber<T extends Constructor<{}>>(Base: T) {
class Unsubscriber extends Base implements OnDestroy {
protected unsubscribe: Subject<void> = new Subject();
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
}
return Unsubscriber;
}
If I compile this code with "declaration": true to get type definitions for my library, I get the following error:
ERROR in (truncated)/mixins.ts (...): Return type of exported function has or is using private name 'Unsubscriber'.
One solution is to add an interface...
export interface IUnsubscriber extends OnDestroy {
unsubscribe: Subject<void>;
}
...and have my mixin function have a return type of Constructor<IUnsubscriber>. This works, but it forces me to make the properties/methods exposed by my mixin be public even in cases where I want them to be protected.
Short of adding protected members to interfaces (which I'm not sure is the right thing to do), this seems to be a limitation of the currently supported mixin strategy.
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 con l’esempio mixins.ts nell’issue e compilalo con la generazione delle dichiarazioni abilitata per riprodurre l’errore di nome privato. Leggi i percorsi di mixin e di generazione delle dichiarazioni o controllo dei tipi coinvolti, quindi verifica che i mixin esportati con membri protetti producano definizioni dei tipi utilizzabili senza richiedere che tali membri siano pubblici.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100