Skip to content

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

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

Closed
ritikbanger opened this issue Sep 21, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@ritikbanger
Copy link

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.

@jcalz
Copy link
Contributor

jcalz commented Sep 21, 2022

Duplicate of #41164.

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

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 21, 2022
@typescript-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants