Skip to content
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

Option to label tuple elements #529

Open
DrJonki opened this issue Jun 5, 2023 · 1 comment
Open

Option to label tuple elements #529

DrJonki opened this issue Jun 5, 2023 · 1 comment

Comments

@DrJonki
Copy link

DrJonki commented Jun 5, 2023

I'm working on a custom RPC-like client-server communication layer, where I publish the back-end schema as JSON, and using this tool (thanks, BTW 🙂) I generate TypeScript for the frontend code to utilize. It's working great, for the most part, but there's one thing missing that I would find very useful.


{
  "id": "test-schema",
  "items": [
    {
      "type": "number",
      "title": "NumberItem"
    },
    {
      "type": "string",
      "title": "StringItem"
    }
  ],
  "minItems": 2,
  "additionalItems": false
}

Currently the above schema is generated into this.

export type TestSchema = [NumberItem, StringItem];
export type NumberItem = number;
export type StringItem = string;

I would like to have the option to use tuple element labels instead of separate named types, so that the generated tuple would look like this instead of the above.

export type TestSchema = [numberItem: number, stringItem: string];

This would allow for better intellisense when the generated tuple is used as a type for a function spread parameter.
Untitled


I'd be willing to try to implement this if maintainers think it's a good idea.

@bcherny
Copy link
Owner

bcherny commented Jun 10, 2023

This seems like a nice improvement. It would likely have to live behind a flag, since it's TS4+ which not everyone might be on.

We could say something like:

  • If inlineSimpleTupleMemberNames=true
  • And all the tuple members have titles defined
  • Then inline simple tuple types (we'd need to consider whether this inlining applies to booleans/numbers/strings only, or also to more complex types)

Let's keep this open to see if there's enough folks that need this to be worth the new flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants