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

If object with nested refine fails, it doesn't apply transform before superRefine, causing superRefine to not be typesafe #3573

Open
matowang opened this issue Jun 14, 2024 · 0 comments

Comments

@matowang
Copy link

matowang commented Jun 14, 2024

Object with nested define doesn't apply transform before superRefine, causing superRefine to not be typesafe.

  const res = z
    .object({
      name: z.string(),
      age: z.number().refine((data) => {
        return data > 18;
      }), // Fails refine
    })
    .transform((data) => {
      return {
        userName: data.name,
        userAge: data.age,
      };
    })
    .superRefine((data) => {
      // Data here is { "name": "John", "age": 6 }, Expected { "userName": "John", "userAge":  6} after transformation
      console.log("superRefine", JSON.stringify(data, null, 2));
    })
    .safeParse({
      name: "John",
      age: 6,
    });
  console.log(res);

This parsing should abort early or perform the transformation anyway. Transform isn't applied here.

@matowang matowang changed the title If object with nested refine fails, it doesn't apply transform before superRefine, causing supertRefine to not be typesafe If object with nested refine fails, it doesn't apply transform before superRefine, causing superRefine to not be typesafe Jun 14, 2024
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