© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
1 reply
tzezar

How to narrow type in select from enum?

During select I need to narrow enum type from multiple choices to one choice eg just 'product'

schema
export const typAsortymentuEnum = pgEnum('typ_asortymentu', ['produkt', 'usluga']);
export const asortyment = pgTable('asortyment', {
    id: serial('id').primaryKey().notNull(),
    typ: typAsortymentuEnum('typ').notNull(),
   
})
export const typAsortymentuEnum = pgEnum('typ_asortymentu', ['produkt', 'usluga']);
export const asortyment = pgTable('asortyment', {
    id: serial('id').primaryKey().notNull(),
    typ: typAsortymentuEnum('typ').notNull(),
   
})


query
    const produkt = alias(asortyment, "produkt")
 const results = await db
        .select({
            id: produkt.id,
            typ: produkt.typ,
        })
        .from(produkt)
        .where(eq(produkt.typ, 'produkt'))
        .execute()
    const produkt = alias(asortyment, "produkt")
 const results = await db
        .select({
            id: produkt.id,
            typ: produkt.typ,
        })
        .from(produkt)
        .where(eq(produkt.typ, 'produkt'))
        .execute()

result
typ
typ
value is typed as
typ: "produkt" | "usluga";
typ: "produkt" | "usluga";
and I need to narrow it to just
product
product


I would be glad for any tip how to accomplish this. Thanks!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is there a simpler way to get an enum type than (typeof enumType)["enumValues"][number]?
Drizzle TeamDTDrizzle Team / help
3y ago
Possible to have type from enum value?
Drizzle TeamDTDrizzle Team / help
3y ago
MySQL select().from() type
Drizzle TeamDTDrizzle Team / help
2y ago
Get plain typescript type from enum
Drizzle TeamDTDrizzle Team / help
3y ago