Get plain typescript type from enum
Hi,
I am working on a NestJS + Drizzle app and I have the following in my schema:
Elsewhere in my code, I am writing a NestJS service that aims to resolve a user based on their current session cookie and I'd like to return the following type:
Is there a way to somehow make the
permissions
field always have a type in sync with the pgEnum? I tried InferColumnType but that clearly isn't correct
Ideally in this scenario, I'd have permissions
be the following type: "admin"|"moderator"|"user"|"banned"
but of course derived somehow from the original enum declaration3 Replies
Okay I figured out, though I'd appreciate feedback on if this is the "correct way" to do this:
@rph I posted on this a while back, let me find it.
@rph :
https://discord.com/channels/1043890932593987624/1043890932593987627/1144690639397720246
you need something similar if you want to use the enum values as values in client code - since you can't import them in the browser bundle from the drizzle schema
My app is purely server side rendered, so I have no worries about client code, the whole thing is a Nest codebase