Rph
Rph
Explore posts from servers
DTDrizzle Team
Created by Rph on 9/3/2023 in #help
Get plain typescript type from enum
Hi, I am working on a NestJS + Drizzle app and I have the following in my schema:
export const userPermissionLevel = pgEnum("permissionLevel", ["admin","moderator","user","banned"]);
export const userPermissionLevel = pgEnum("permissionLevel", ["admin","moderator","user","banned"]);
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:
export interface UserMetadata {
hasEmail: boolean,
permissions: ???,
username: string
}
export interface UserMetadata {
hasEmail: boolean,
permissions: ???,
username: string
}
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 declaration
6 replies