Skip to content

Incompatibility between literals helper and zod #861

@tyb51

Description

@tyb51

Example

when generating a zod schema

import { convexToZod } from "convex-helpers/server/zod4";
export const PersonSchema = convexToZod(Person.table.validator);

We get a proper ZodValidator when we define the table as followed

export const Person= Table("persons", {
  firstName: v.string(),
  lastName: v.string(),
  gender: v.union(v.literal("male"), v.literal("female"), v.literal("other")),
});

But when we define it as

export const Person= Table("persons", {
  firstName: v.string(),
  lastName: v.string(),
   gender: literals("male", "female", "other"),
});

The zod PersonSchema gives a never type to the gender field

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions