Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get the correct type when I used z.transform() #59

Open
zce opened this issue Nov 17, 2023 · 1 comment
Open

Unable to get the correct type when I used z.transform() #59

zce opened this issue Nov 17, 2023 · 1 comment

Comments

@zce
Copy link

zce commented Nov 17, 2023

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;
}
@zce
Copy link
Author

zce commented Nov 17, 2023

I can obtain the correct type inference using z. infer<typeof xxx>.

image

I'm very sorry, I haven't had time to carefully read your project yet. I discovered this issue on my first use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant