TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open ritikbanger opened this issue 3 years ago • 1 comments

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.

ritikbanger avatar Sep 21 '22 13:09 ritikbanger

Duplicate of #41164.

There's a whole template you're prompted to fill out when you open a bug here; did you miss it?

jcalz avatar Sep 21 '22 17:09 jcalz

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

typescript-bot avatar Sep 24 '22 18:09 typescript-bot