microsoft / microsoft/TypeScript
Unable to specify return type of class extends T implements IFooable
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: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
// A *self-contained* demonstration of the problem follows...
export type Constructor<T> = new (...args: any[]) => T;
export interface IFooable { FooProp: string; }
export function FooableMixin<T extends Constructor<{}>>(Base: T) {
return class extends Base implements IFooable {
FooProp: string;
constructor(...args: any[]) {
super(...args);
}
}
}
export class BaseBar { BarProp: string = "baz"; }
export class FooableBar extends FooableMixin ( BaseBar ) {}
let foobar = new FooableBar();
foobar.FooProp = foobar.BarProp;
/* This is ok since FooableBar extends an Anonymous class inheriting from BaseBar and implementing IFooable */
If I turn on "declaration: true" in tsconfig.json this constuct breaks since the Anonymous class counts as private and not exported type (error TS4060) which is kind of natural since it is Anonymous.
What we need is a way to describe Classes as return types.
Expected behavior:
A d.ts file with a type declaration for the Mixin function Fooable that defines a Anonymous Class return type in the style of:
declare function Fooable(T extends Constructor<{}>): (class extends T implements IFooable);
Actual behavior:
TS4060 error when compiling with the "declaration" flag.
If casting the Anonymous Class return value to or T, the interface is lost.
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 autonomo di FooableMixin nell’issue e compilalo con l’emissione delle declarations abilitata. Analizza l’emissione delle declarations per la classe anonima restituita da FooableMixin; il lavoro è completato quando il .d.ts generato descrive la classe che estende T e implementa IFooable, senza TS4060 né la perdita dell’interfaccia.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100