Skip to content

Circular Reference with Generic Parameterization - error TS2456: Type alias 'Result' circularly references itself. #61062 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AaronNGray opened this issue Jan 28, 2025 Β· 0 comments

Comments

@AaronNGray
Copy link
Owner

πŸ”Ž Search Terms

microsoft#61062 Self Referential Types, Recursive Types, Mutually Recursive Types.

πŸ•— Version & Regression Information

Failing on Main 32ebd28

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAggdiAPAFShAHsCcAmBnKAeQCMArCAY2AD4oBeKAbwCgo2oBtAawhAC48wAE4BLOAHMAunyjIA3MwC+cqM2ahIUAEoQ8AVwA2welEGiJUAD7bdh4B0lXYCRDv1HqKgPRe0QoQD2QrIAygBMACwArABsMsjg0ACGBiJJBADkbnYZUBQiQhSGSUIGIFBCEABmEJVwFLpQIsB4EAZVAHTMQA

πŸ’» Code

Fails :-

type Any<T extends Object> = {
    [key:string]: T;
}; 

type Result = 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

To support self referential, recursive, and mutually recursive types.

Additional information about the issue

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant