You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Circular Reference with Generic Parameterization - error TS2456: Type alias 'Result' circularly references itself.Β #61062
typeAny<TextendsObject>={[key:string]: T;};typeResult=string|Result[]|Any<Result>;// error TS2456: Type alias 'Result' circularly references itself.
Works :-
type ResultObject = {
[key:string]: Result;
};
type Result = string | Result[] | ResultObject;
Fails :-
type ResultObject = {
[key:string]: Result;
};
type ResultArray<T> = T[];
type Result = string | ResultArray<Result> | ResultObject; // error TS2456: Type alias 'Result' circularly references itself.
It looks like it is a Generic Parameterization issue.
π Actual behavior
Throwing Error on compilation error TS2456: Type alias 'Result' circularly references itself.
π Expected behavior
Should not throw an error and demonstrates the type system is incomplete.
Activity
jcalz commentedon Jan 28, 2025
duplicate of #41164
AaronNGray commentedon Jan 28, 2025
Looks semantically totally different to me.
jcalz commentedon Jan 28, 2025
Any<T>is the same asRecord<string, T>and you have the same problem with it.AaronNGray commentedon Jan 28, 2025
So basically there is no support for recursive parameterized types and mutually recursive parameterized types in TypeScript.
This is a crazy limitation as so many programming patterns I use use this.
I need to find my feet with TypeScripts code base and see if I can implement this.
jcalz commentedon Jan 28, 2025
You might want to read through the other issue thoroughly, especially the linked PR at #57293.