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

Use Record or mapped types for map #53

Open
minism opened this issue Mar 7, 2024 · 1 comment
Open

Use Record or mapped types for map #53

minism opened this issue Mar 7, 2024 · 1 comment

Comments

@minism
Copy link

minism commented Mar 7, 2024

I'd like to be able to generate either a Record or a typescript mapped type for a golang map type.

Example:

CheapestReturnMiles map[util.CabinClassT]util.MilesTax `json:"CheapestReturnMiles"`

Config:

type_mappings:
  util.CabinClassT: 'CabinClass'
  util.MilesTax: '{miles: number, tax: number}'

Current output:

CheapestReturnMiles: { [key: CabinClass]: {miles: number, tax: number}};

Expected output:

CheapestReturnMiles: Record<CabinClass, { miles: number; tax: number }>;

The current output fails typescript compliation, since we have CabinClass defined as type CabinClass = 'Economy' | 'First', and typescript doesnt allow literal types as index signatures.

Alternatively a mapped type could be used here:

CheapestReturnMiles: { [key in CabinClass]: { miles: number; tax: number } };
@minism minism changed the title Use Record for map types Use Record or mapped types for map Mar 7, 2024
@minism
Copy link
Author

minism commented Mar 7, 2024

Also to be clear, happy to take a stab at implementing this if you have pointers or know why this is hard to do

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

1 participant