zod
zod copied to clipboard
Property 'catch' does not exist on type 'ZodNumber'.
Sorry for bothering you guys. I ran an example from the README.md
and it's not compiling. Am I doing something wrong?
Code:
import { z } from "zod";
const numberWithCatch = z.number().catch(42);
numberWithCatch.parse(5); // => 5
numberWithCatch.parse("tuna"); // => 42
Error:
/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
trash/zod.ts:3:36 - error TS2339: Property 'catch' does not exist on type 'ZodNumber'.
3 const numberWithCatch = z.number().catch(42);
~~~~~
at createTSError (/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/in
dex.ts:859:12)
at reportTSError (/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/in
dex.ts:863:19)
at getOutput (/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.
ts:1077:36)
at Object.compile (/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/i
ndex.ts:1433:41)
at Module.m._compile (/home/<user>/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/sr
c/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/home/<user>/.nvm/versions/node/v16.16.0
/lib/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
diagnosticCodes: [ 2339 ]
}
Hi I am facing a similar issue.
TypeError: import_zod2.z.array(...).catch is not a function
Did you found the problem?
After looking at the code, seems like the commit https://github.com/colinhacks/zod/commit/0ce88be33d4b29ea5026f18e0ca97957cbb02cda that introduces .catch
is simply not yet released :)
Is there an estimated date for the next release?
Could we release the current code at the alpha or beta tag to try out?
Zod 3.20 just landed, sorry for the confusion! npm install zod@latest