microsoft / microsoft/TypeScript
Resolution order dependent circular heritage
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
🔎 Search Terms
resolution order dependent circular heritage, circular base type, circular mixin
🕗 Version & Regression Information
- This changed in #39675
However, it appears this PR was the first time that circular heritage was (consistently) reported. Therefore this issue has essentially always existed.
⏯ Playground Link
💻 Code
// Fixed if you comment this line out or switch to `ActorPTR2e`.
declare const x: InstanceType<typeof ActorPTR2e>;
// Used to show that only a dependency on `T` is necessary for the circularity.
// As in, the final resolved value does not matter.
type DependsOn<T> = any;
declare class Actor {
prop: DependsOn<ActiveEffect["prop"]>;
}
declare namespace Item {
// Fixed if you switch this to an interface.
type Implementation = InstanceType<DocumentClassConfig["Item"]>;
}
declare class Item {
x: DependsOn<ActiveEffect["prop"]>;
}
// Fixed if you remove the `SubType` generic parameter.
class ActorPTR2e<SubType = any> extends Actor {}
// Fixed if you remove the `SubType` generic parameter.
class ItemPTR2e<SubType = any> extends Item {}
interface DocumentClassConfig {
// Fixed if you change `typeof ActorPTR2e` to `typeof ActorPTR2e<any>`
Actor: typeof ActorPTR2e;
// Fixed if you change `typeof ItemPTR2e` to `typeof ItemPTR2e<any>`
Item: typeof ItemPTR2e;
}
declare class ActiveEffect extends ClientDocumentMixin(BaseActiveEffect) {
prop: number;
}
declare function ClientDocumentMixin<
// Fixed if you loosen the constraint of `BaseClass`.
BaseClass extends new (...args: any[]) => object,
>(Base: BaseClass): BaseClass;
declare class BaseActiveEffect {
constructor(...args: DependsOn<Item.Implementation>);
}
🙁 Actual behavior
Numerous errors, namely:
Type alias 'Implementation' circularly references itself.
Type 'ActiveEffect' recursively references itself as a base type.
'ActiveEffect' is referenced directly or indirectly in its own base expression.
'args' is referenced directly or indirectly in its own type annotation.
🙂 Expected behavior
No error, as seen when you comment out the line declare const x: InstanceType<typeof ActorPTR2e>;. The error going away indicates that this circularity is resolution order dependent.
I understand how odd the code is out of context but I did actually run into this in a real codebase.
Additional information about the issue
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verlinkten TypeScript Playground-Reproduktion und verfolge die gemeldeten Diagnosen zu zirkulären Typaliasen, Basistypen und Annotationen im Zusammenhang mit InstanceType, der Vererbung generischer Klassen und Mixin-Constraints. Erledigt ist die Aufgabe, wenn die Reproduktion diese von der Auflösungsreihenfolge abhängigen Fehler nicht mehr meldet, ohne das Beispiel so zu ändern, dass die Zirkularität vermieden wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100