Skip to content

Conversation

@orhanhenrik
Copy link

Fixes #1884

This PR implements a new option --useTuples which converts constant size arrays into constant size typescript arrays.

I'm not too happy with how the logic ended up partially in handlebars and partially in typescript, so if you have any suggestions for how I could make this work better with the project's code structure I would appreciate that! The problem I was facing was that I didn't have access to any options inside getModel without having to pass the useTuples option throughout the whole program.

Example

MyModel: {
  type: 'object',
  properties: {
    coordinates: {
      type: 'array',
      items: {
        type: 'number',
      },
      minItems: 2,
      maxItems: 2,
    },
  },
},

Without --useTuples

export type MyModel = {
  coordinates: Array<number>;
}

With --useTuples

export type MyModel = {
  coordinates: [number, number];
}

@nicholaschiang
Copy link

+1

@orhanhenrik
Copy link
Author

Works in the maintained fork of this library https://github.com/hey-api/openapi-ts

@orhanhenrik orhanhenrik closed this May 8, 2024
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

Successfully merging this pull request may close these issues.

Option to convert constant size arrays into tuples

3 participants