ZodObject not assignable to ZodTypeAny #1993
-
I've encountered this issue since updating to 3.20.2 (have also tried going down to 3.20.1 and 3.20.0, but it only disappears in 3.19), where I get I've tried searching for a solution to the issue but cannot seem to find anything. Reproduction steps:
This worked in previous versions but I just cannot seem to get it working in this update. I'd love to hear any feedback on this, and maybe hear if I'm doing anything wrong or if it's a known issue. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 1 reply
-
Version 3.20.0 definitely breaks something with |
Beta Was this translation helpful? Give feedback.
-
Seems unrelated to #1955. I cannot reproduce this issue here. Could you provide a minimal reproduction please? |
Beta Was this translation helpful? Give feedback.
-
@cbosman-docksters const a = z.object( { foo: z.string() } )
const b = z.object( { someName: a } )
console.log( b.parse( { someName: { foo: 'foo' } } ) )
// { someName: { foo: 'foo' } } |
Beta Was this translation helpful? Give feedback.
-
Make sure you have set |
Beta Was this translation helpful? Give feedback.
-
Hi there. I do have Reproduction: export const foo = z.object({
test: z.string(),
});
2.ts
import {foo} from "1.ts";
const foobar = z.object({
bar: foo,
}); This is the output of the ts compiler:
|
Beta Was this translation helpful? Give feedback.
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
I have tried this, and everything is working as expected. // 1.ts
import { z } from 'zod'
export const foo = z.object( {
test: z.string(),
} ) // 2.ts
import { foo } from "./1.ts"
const foobar = z.object( {
bar: foo,
} )
// no errors Can you please provide your package.json and tsconfig.json? Alternatively, you could provide a link to a codesandbox or something that has everything the way you do. |
Beta Was this translation helpful? Give feedback.
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
I use it in a monorepo via yarn workspaces, could that have anything to do with it? I indeed cannot seem to reproduce it in codesandbox. package.json
tsconfig.json
|
Beta Was this translation helpful? Give feedback.
{{title}}
-
Nvm, I'm a dumbass. I was mixing-and-matching zod versions in my codebase. In this case, I was using this "common" package I built myself, which was on an older version of zod (namely 3.19) and trying to use those older validators in the newer 3.20 version of zod. Thanks for helping me! |
Beta Was this translation helpful? Give feedback.
{{title}}
-
If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
I have tried this, and everything is working as expected.
Can you please provide your package.json and tsconfig.json?
Alternatively, you could provide a link to a codesandbox or something that has everything the way you do.