microsoft / microsoft/TypeScript
Type alias circularly references itself
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
### 🔎 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
https://www.typescriptlang.org/play/?ts=5.8.2#code/C4TwDgpgBAYg9nAKuaBeKBvAsAKClAMwQH4AuKAIwQBsIBDAOwG5cBfFnXUSKAIToDOEAKK0AthAbAAPIgB8UdPCQooAMky58AYwAWAS2oATAE6TyAYQCuA4HDGiIEqQG0Auh3zcI5RB3a4XKrWtvaOzsCKfIIi4pIyAOS6AIwJchxAA
### 💻 Code
```ts
type FooType = {
foo?: boolean;
};
type BaseElement = 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_
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par la reproduction liée dans TypeScript Playground et comparez les deux ordres des membres dans le type d’intersection générique. Suivez le diagnostic de référence circulaire pour les alias de types récursifs et déterminez pourquoi l’ajout de FooType le modifie ; le travail est terminé lorsque la structure récursive valide ne signale plus TS2456 et que l’ordre des membres ne modifie pas le résultat.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100