zod icon indicating copy to clipboard operation
zod copied to clipboard

Fixed type Inference with `custom` and `instanceof` in `catchall`

Open taro-28 opened this issue 9 months ago • 0 comments

Hello!

I noticed that when using custom or instanceof with catchall, the type inference using infer does not work. I have fixed it and added tests.

Before

const schema = z.object({ name: z.string() }).catchall(z.instanceof(Date));

// { name: string }
type Schema = z.infer<typeof schema>;

After

const schema = z.object({ name: z.string() }).catchall(z.instanceof(Date));

// { name: string } & { [k: string]: Date };
type Schema = z.infer<typeof schema>;

taro-28 avatar May 21 '24 16:05 taro-28