microsoft / microsoft/TypeScript
Type alias circularly references itself
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
circular reference, generic, error TS2456, recursive
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about circular reference
⏯ Playground Link
💻 Code
type FooType = {
foo?: boolean;
};
type BaseElement<T> = FooType & {
children: CustomElement[];
type: T;
};
type CustomElement = BaseElement<'h1'>;
🙁 Actual behavior
When defining a recursive type structure using a generic type, TypeScript incorrectly reports a Type alias 'CustomElement' circularly references itself.(2456) error, even though the type should be resolvable.
It gets weird when you move type: T; line above the children: CustomElement[]; and the error disappears. Also removing FooType will resolve the issue.
🙂 Expected behavior
In the first place the code should not throw any errors, in the second place the behavior should not change by reordering records of a type.
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 verknüpften TypeScript Playground-Reproduktion und vergleiche die beiden Member-Reihenfolgen im generischen Intersection-Typ. Verfolge die Diagnose für Zirkelverweise bei rekursiven Typ-Aliasen und ermittle, warum das Hinzufügen von FooType sie verändert; abgeschlossen ist die Aufgabe, wenn die gültige rekursive Struktur nicht mehr TS2456 meldet und die Member-Reihenfolge das Ergebnis nicht verändert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100