Skip to content

Typescript reports circular dependency error in Record type but not in dynamic object type #50881

@ritikbanger

Description

@ritikbanger

I have two kinds of type, while using the Record, typescript is giving circular reference error. But when I do the same with a dynamic object, no error pops. Why typescript show two completely contrasting behaviours?

The expected output should be error on both or on none.

type ScopeItem =
    | string
    | {
            all: string;
            team: string;
      };

type ScopesTree = Record<string, ScopeItem | Record<string, ScopesTree>>; // error: Type alias 'ScopesTree' circular references itself
type ScopesTree2 = Record<string, ScopeItem | { [key: string]: ScopesTree2 }>; // no error

lziM6

Is it something to do with the computation of the typescript type in both the cases? Please enlighten.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions