zod-to-ts
zod-to-ts copied to clipboard
Unable to get the correct type when I used `z.transform()`
When I use transform to convert the data type, I am not able to obtain the correct type.
import { z } from 'zod';
import { printNode, zodToTs } from 'zod-to-ts';
// define your Zod schema
const UserSchema = z.object({
username: z.string(),
age: z.number(),
avatar: z.string().transform((value) => {
// convert...
return {
src: value,
width: 100,
height: 100,
};
}),
});
// pass schema and name of type/identifier
const { node } = zodToTs(UserSchema, 'User');
const code = printNode(node);
console.log(code);
{
username: string;
age: number;
avatar: string;
}
I can obtain the correct type inference using z. infer<typeof xxx>
.
I'm very sorry, I haven't had time to carefully read your project yet. I discovered this issue on my first use