Skip to content

Record in circular type alias #50967

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
FStefanni opened this issue Sep 27, 2022 · 2 comments
Closed

Record in circular type alias #50967

FStefanni opened this issue Sep 27, 2022 · 2 comments

Comments

@FStefanni
Copy link

Bug Report

🔎 Search Terms

circular type alias, record, json

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

In version 4.8.3 it does not compiles.

⏯ Playground Link

Playground link with relevant code

💻 Code

// NOT working
export type Json =
    Array<Json>
    | Record<string, Json>
    | boolean
    | number
    | string
    | null;

// Working
export type Json2 =
    Array<Json2>
    | boolean
    | number
    | string
    | {[property: string]: Json2}
    | null;

🙁 Actual behavior

Type alias Json does not compile.
This is due to the Record type, which if changed into an indexed map start to work.

🙂 Expected behavior

I was expecting this to compile, since a Record with string as key seems to me as a valid alternative syntax.
Actually, also some linting rules suggest to avoid indexed maps in favor of Record<string,>.

But I am not 100% sure this is actually something that should be considered as a bug, or if there is some underlying difference that I do not know.

Regards.

@MartinJohns
Copy link
Contributor

Duplicate of #41164.

I was expecting this to compile, since a Record with string as key seems to me as a valid alternative syntax.

Record is a mapped type, whereas the other syntax is an indexed type. It's not an alternative syntax.

@FStefanni
Copy link
Author

Oh yes, right!
I just added to that, thank you.
Regards.

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

2 participants