© 2026 Hedgehog Software, LLC

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

shared zod refinements

⚡drizzle-zod
i've done some searching and found a couple leads around this issue in discord, but couldn't find anything that works - i want to share zod refinements to
createSelectSchema
createSelectSchema
,
createInsertSchema
createInsertSchema
and
createUpdateSchema
createUpdateSchema
(i.e. supplying a
z.enum()
z.enum()
for validation/typings). currently there's no way to do this other than creating an object and crossing fingers when it comes to typings, or just passing the refinements to each
createXSchema
createXSchema
call - is there something i'm missing or some way to properly type a shared
refinements
refinements
object?

const myEnum = {
  hello: 'HELLO',
  world: 'WORLD',
} as const;

type MyEnum = typeof myEnum[keyof typeof myEnum];

export const myTable = pgTable('my_table', {
  type: varchar({ length: 256 }).notNull().$type<MyEnum>(),
});

/**
 * option 1 - yolo the typings
 */
const refinements = {
  type: z.enum(myEnum),
} as const;

const select = createSelectSchema(myTable, refinements);
const create = createInsertSchema(myTable, refinements);
const update = createUpdateSchema(myTable, refinements);

/**
 * option 2 - a complete mess
 */
const select = createSelectSchema(myTable, {
  type: z.enum(myEnum),
});
const create = createInsertSchema(myTable, {
  type: z.enum(myEnum),
});
const update = createUpdateSchema(myTable, {
  type: z.enum(myEnum),
});
const myEnum = {
  hello: 'HELLO',
  world: 'WORLD',
} as const;

type MyEnum = typeof myEnum[keyof typeof myEnum];

export const myTable = pgTable('my_table', {
  type: varchar({ length: 256 }).notNull().$type<MyEnum>(),
});

/**
 * option 1 - yolo the typings
 */
const refinements = {
  type: z.enum(myEnum),
} as const;

const select = createSelectSchema(myTable, refinements);
const create = createInsertSchema(myTable, refinements);
const update = createUpdateSchema(myTable, refinements);

/**
 * option 2 - a complete mess
 */
const select = createSelectSchema(myTable, {
  type: z.enum(myEnum),
});
const create = createInsertSchema(myTable, {
  type: z.enum(myEnum),
});
const update = createUpdateSchema(myTable, {
  type: z.enum(myEnum),
});
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

Drizzle-zod should accept refinements on tables
Drizzle TeamDTDrizzle Team / help
6mo ago
drizzle-zod insert/update schema refinements type
Drizzle TeamDTDrizzle Team / help
11mo ago
Why does drizzle-zod refinements overwrite the nullability of the field?
Drizzle TeamDTDrizzle Team / help
8mo ago
Drizzle-zod combined with regular zod? 🙃
Drizzle TeamDTDrizzle Team / help
15mo ago