microsoft / microsoft/TypeScript
Provide a way to specify inheritance explicitly
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: 3.0.0-dev.201xxxxx
Its seems there's really no way currently to setup inheritance when working with complex mixins, and/or extending prototypes manually. While mixin support landed on TypeScript recently, it only addresses very simple cases. It's usefulness ends when you also want mixin that inherit from different classes on their own. To illustrate it with an example:
export class Component extends HTMLElement implements ComponentCore {
constructor() {
super();
ComponentCore.init(this);
}
}
where the ComponentCore.init does mixin style implementation of ComponentCore. Tried the mixin approach documented, but that doesn't seem to work when you want to extend from HTMLElement here.
Now, moving on a real-life example with a lot more context: https://github.com/prasannavl/icomponent/blob/v5.1.1/packages/icomponent/src/component.ts#L6
I had to jump through hoops and do something like
ComponentCore.extend(ComponentImpl);
export interface IComponent extends ComponentImpl, ComponentStatics, ComponentCore, Constructor<IComponent> { }
export const Component: IComponent = ComponentImpl as any;
in order to even get inheritance working properly. This is further complicated, when you extend from these classes, since there's currently it's const Component, and as such it is not always interpreted by the compiler as a class -- As as example - a few lines down in the same: https://github.com/prasannavl/icomponent/blob/v5.1.1/packages/icomponent/src/component.ts#L30
You can't pass Component into generics parameters, since it's no longer a class.
Possible solutions:
- A simple and effective solution would be to just be even annotate the class and having different parents.
// @ts-inherit: IComponentCore, HTMLElement, etc, - Extend the
extendssyntax to inherit multiple classes with say "extends X, !Y, !Z` -- The exclamation is the indicator of these special classes - Allow implements to inherit a class without actually implementing it, with the same as above syntax. This is probably the least intrusive way, but unlike
extends, it forces you explicitly define interfaces to be able to do so.
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
La issue non indica alcun file del repository TypeScript né alcun punto di ingresso dei test; inizia riproducendo l’approccio documentato con mixin e esaminando l’esempio icomponent collegato. Confronta i meccanismi di ereditarietà proposti e definisci quali casi complessi di mixin e generic-class devono essere supportati prima di cercare i test del compilatore. Il lavoro è concluso quando esiste un design concordato con copertura dei casi supportati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 18/100