Skip to content

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

Closed
@AaronNGray

Description

@AaronNGray

πŸ”Ž Search Terms

Circular Reference, Generic Parameterization, error TS2456: Type alias 'Result' circularly references itself.

πŸ•— 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

Should not throw an error and demonstrates the type system is incomplete.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions