microsoft / microsoft/TypeScript
Mixing base class defeats circularity protection
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
🔎 Search Terms
mixin, referenced directly or indirectly in its own type annotation, recursively references itself as a base type, referenced directly or indirectly in its own base expression.
🕗 Version & Regression Information
- This changed in the PR #39675
Given that this was when base types were consistently checked for errors this has effectively existed forever, just only started being reported in #39675.
⏯ Playground Link
💻 Code
declare class BaseCombatant {
constructor(...args: [Combatant["prop"]]);
// ^^^^^^^^^^^^^^^^^ 'args' is referenced directly or indirectly in its own type annotation.
}
declare class InternalClientDocument {
constructor(...args: any[]);
}
declare function ClientDocumentMixin<BaseClass>(
Base: BaseClass
): typeof InternalClientDocument & BaseClass;
// ^ Remove `typeof InternalClientDocument` and the circularity goes away.
declare class Combatant extends ClientDocumentMixin(BaseCombatant) {
// ^^^^^^^ Type 'Combatant' recursively references itself as a base type.
// ^^^^^^^ 'Combatant' is referenced directly or indirectly in its own base expression.
prop: number;
}
🙁 Actual behavior
Numerous errors.
🙂 Expected behavior
No error. This pattern is not intractable, in fact if you remove the useless typeof InternalClientDocument in typeof InternalClientDocument & BaseClass it works.
In reality I'm actually dealing with a useful mixin, not an empty class, so I would prefer this to work for a complete mixin as well. I'm guessing the issue has something to do with weaker caching around arbitrary expressions as the base class compared to the typical base class with a concrete name.
Additional information about the issue
No response
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 dalla riproduzione collegata in TypeScript Playground e traccia le diagnostiche di circolarità per l’espressione di base del mixin calcolata e il relativo tipo di ritorno di intersezione. Il lavoro è completato quando il pattern di mixin mostrato, incluso l’utile caso di mixin non vuoto, non produce errori errati di base ricorsiva o di annotazione autoreferenziale.
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