microsoft / microsoft/TypeScript
Type alias circularly references itself
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
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_
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 di TypeScript Playground e confronta i due ordinamenti dei membri nel tipo di intersezione generico. Segui la diagnostica del riferimento circolare per gli alias di tipo ricorsivi e determina perché l’aggiunta di FooType la modifica; il lavoro è completato quando la struttura ricorsiva valida non segnala più TS2456 e l’ordine dei membri non cambia il risultato.
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
- Specificata chiaramente
- Idoneità per principianti
- 35/100