microsoft / microsoft/TypeScript
Type alias circularly references itself
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
### 🔎 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_
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción vinculada de TypeScript Playground y compara los dos órdenes de miembros en el tipo de intersección genérico. Sigue el diagnóstico de referencia circular para los alias de tipo recursivos y determina por qué añadir FooType lo cambia; se considera terminado cuando la estructura recursiva válida ya no informa de TS2456 y el orden de los miembros no cambia el resultado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100