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

Zod Preprocess returning unknown type #3537

Open
enchorb opened this issue May 30, 2024 · 1 comment
Open

Zod Preprocess returning unknown type #3537

enchorb opened this issue May 30, 2024 · 1 comment

Comments

@enchorb
Copy link

enchorb commented May 30, 2024

The type returned from z.preprocess is giving out type "unknown"

Some Examples:

export const string_validation = z.preprocess(
  (value) => {
    if (typeof value !== 'string') return value;
    return value.trim().replace(/\s\s+/g, ' ');
  },
  z.string().min(1)
);

export const boolean_validation = z.preprocess((bool) => {
  if (typeof bool === 'boolean') return bool;
  return bool === 'true';
}, z.boolean());

export const number_validation = z.preprocess(
  (num) => (!num && num !== 0 ? num : Number(num)),
  z.number()
);
@samchungy
Copy link
Contributor

This depends on what type util you're using to infer the type? Are you using infer, input or output?

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

2 participants