colinhacks / tozod

MIT License
153 stars 7 forks source link

Usage of toZod with Generic Types #30

Closed w1am closed 11 months ago

w1am commented 11 months ago

I'm currently trying to use toZod with a generic type, specifically with the Option type I've defined in my code. Here's what my code looks like:

import { z } from 'zod';
import { toZod } from "tozod";

export type Option<T> = {
  value: T;
  label: string;
}

export const OptionSchema = <T>(valueSchema: z.ZodType<T>) => z.object({
  value: valueSchema,
  label: z.string()
});

How can I use toZod with the generic type Option<T>?