Is there a simpler way to get an enum type than (typeof enumType)["enumValues"][number]?
Pretty quick question (and maybe quick answer) - we have this pattern in a few places and it looks a bit verbose.
2 Replies
Not sure if this is what you mean, but we have this pattern:
This allows us to do stuff like
OrderMethod.PICKUP
and use OrderMethodValue
as a type when excepting one of the values
Sorry, meant to include strEnum
Thanks a lot for sharing @Noahh - those snippets are super useful
Another (indirect) way to get the enum values type is by inspecting the table's type:
For example:
I wish there was a way to get this type directly from the
pgEnum
though