Skip to content

egon-orm-workspace / @egon-orm/zod / ZodHint

Interface: ZodHint<T> ​

Defined in: zod/src/to-zod.ts:100

The hint a custom type gives toZod: the Zod schema for its values (or a function that returns it). Without one, a custom type becomes a z.custom() check that accepts exactly the values the type itself accepts.

defineType keeps only the members it knows, so add the hint to the type it returns:

Example ​

ts
const Slug = defineType<string>({ name: "slug", db: { kind: "text" }, cast: castSlug });
const SlugWithZod: FieldType<string, string> & ZodHint<string> = {
  ...Slug,
  zod: z.string().regex(/^[a-z0-9-]+$/),
};
class Article extends Schema("articles", { slug: t.type(SlugWithZod) }) {}

Type Parameters ​

T ​

T = unknown

Properties ​

zod ​

ts
readonly zod: 
  | ZodType<T, unknown, $ZodTypeInternals<T, unknown>>
  | (() => ZodType<T>);

Defined in: zod/src/to-zod.ts:101