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

can convert preprocess to ts #19

Open
hunght opened this issue Oct 19, 2022 · 1 comment
Open

can convert preprocess to ts #19

hunght opened this issue Oct 19, 2022 · 1 comment

Comments

@hunght
Copy link

hunght commented Oct 19, 2022

z.preprocess(
                (a) => parseInt(z.string().parse(a), 10),
                z.number().positive().max(100)
              ),

error:

console.log
    ZodError: [
      {
        "code": "invalid_type",
        "expected": "string",
        "received": "undefined",
        "path": [],
        "message": "Required"
      }
    ]
        at handleResult (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:29:23)
        at ZodString.safeParse (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:140:16)
        at ZodString.parse (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:120:29)
        at Object.transform (/Users/owner/Documents/source-code/private/express-zod-api/tests/unit/client.spec.ts:19:44)
        at ZodEffects._parse (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:2261:38)
        at ZodEffects._parseSync (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:109:29)
        at ZodEffects.safeParse (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:139:29)
        at ZodEffects.isOptional (/Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod/lib/types.js:276:21)
        at /Users/owner/Documents/source-code/private/express-zod-api/node_modules/zod-to-ts/dist/index.cjs:141:81
        at Array.map (<anonymous>)
@sachinraja
Copy link
Owner

Looks like this is a Zod issue? We shouldn't be getting an error for calling isOptional on a schema.

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