You can give t
the respective z.ZodType
type.
const t: z.ZodType<Foo> = z.object({
count: z.number(),
})
// Error: Property 'id' is missing in type '{ count: number; }' but required in type 'Foo'
Alternatively, you can use a helper function:
const schemaForType = <T>() => <S extends z.ZodType<T, any, any>>(arg: S) => {
return arg;
};
schemaForType<Foo>()(
z.object({
id: z.string(),
count: z.number(),
})
);
schemaForType<Foo>()(
z.object({
id: z.string(),
})
// ^^^^^^^^^^^^^^^ Error: Property 'count' is missing in type '{ id: string; }' but required in type 'Foo'.(2345)
);
Playground