-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Hi there,
This is a great package, and thank you so much for putting it together. I wanted to throw out an idea for feedback and see if it's something you might consider accepting as a PR if I were to put it together.
In summary, when generating enum types, we get output that looks something like this:
const CurrencyTypeEnum = {
USD: 'USD',
MXN: 'MXN',
EUR: 'EUR',
} as const;
export type CurrencyTypeEnum = typeof CurrencyTypeEnum[keyof typeof CurrencyTypeEnum]
This works very well if all I need is the type definition, but what if I want to use the object directly - e.g. to populate a select box or something? As-is, I have to duplicate the object elsewhere in my code.
It would seem nicer to do something like this instead:
export const CurrencyTypeEnum = {
USD: 'USD',
MXN: 'MXN',
EUR: 'EUR',
} as const;
And then adjust the references in the other typedefs to use the typeof of the object, e.g.:
export interface Listing {
...
currency: typeof CurrencyTypeEnum|null
...
}
I currently solve this by using sed as part of my pipeline:
sed -i '' -e '/^export type .*Enum = typeof .*Enum\[keyof typeof .*Enum\]$/d' -e '/^const .*Enum =/{s//export &/;}' ./resources/js/generated-types.ts && \
sed -i '' 's/\(.*: \)\(.*Enum\)/\1typeof \2/' ./resources/js/generated-types.ts
But this is obviously a bit inelegant and brittle.
So on to my questions:
- Is a change like this something you would accept into core?
- Would we want to put it behind some sort of option/flag to preserve backwards compatibility?
- Any pointers on where to look in the codebase to implement it?
Thank you!