[BUG] Incompatible schema type with Zod
tuankietcoderr opened this issue · comments
Are you using the latest version of this library?
- I verified that the issue exists in the latest next-safe-action release
Is there an existing issue for this?
- I have searched the existing issues and found nothing that matches
Describe the bug
I'm getting this error when using with zod
My schema is:
Reproduction steps
I created a module to include safeAction
:
I created a module include taxFormSchema
:
And the error occured:
Expected behavior
Everything works OK!
Reproduction example
Internal project
Operating System
macOS
Library version
6.2.0
Additional context
Full errors:
Argument of type 'ZodObject<{ name: ZodString; rate: ZodNumber; country: ZodOptional<ZodString>; city: ZodOptional<ZodString>; state: ZodOptional<...>; zip: ZodOptional<...>; }, "strip", ZodTypeAny, { ...; }, { ...; }>' is not assignable to parameter of type 'Schema'.
Type 'ZodObject<{ name: ZodString; rate: ZodNumber; country: ZodOptional<ZodString>; city: ZodOptional<ZodString>; state: ZodOptional<...>; zip: ZodOptional<...>; }, "strip", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<any, ZodTypeDef, any>'.
The types of '_def.errorMap' are incompatible between these types.
Type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodErrorMap | undefined' is not assignable to type 'Zod.ZodErrorMap | undefined'.
Type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodErrorMap' is not assignable to type 'Zod.ZodErrorMap'.
Types of parameters 'issue' and 'issue' are incompatible.
Type 'Zod.ZodIssueOptionalMessage' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodIssueOptionalMessage'.
Type 'ZodInvalidUnionIssue' is not assignable to type 'ZodIssueOptionalMessage'.
Type 'Zod.ZodInvalidUnionIssue' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodInvalidUnionIssue'.
Types of property 'unionErrors' are incompatible.
Type 'Zod.ZodError<any>[]' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodError<any>[]'.
Type 'Zod.ZodError<any>' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodError<any>'.
Types of property 'issues' are incompatible.
Type 'Zod.ZodIssue[]' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodIssue[]'.
Type 'Zod.ZodIssue' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodIssue'.
Type 'ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodIssue'.
Type 'Zod.ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }'.
Type 'ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodInvalidUnionIssue'.
Types of property 'unionErrors' are incompatible.
Type 'Zod.ZodError<any>[]' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodError<any>[]'.
Type 'Zod.ZodError<any>' is not assignable to type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodError<any>'.
Types of property 'addIssue' are incompatible.
Type '(sub: Zod.ZodIssue) => void' is not assignable to type '(sub: import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodIssue) => void'.
Types of parameters 'sub' and 'sub' are incompatible.
Type 'import("/Users/macmini/University/sobee-management/node_modules/zod/lib/ZodError").ZodIssue' is not assignable to type 'Zod.ZodIssue'.
Type 'ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodIssue'.ts(2345)
No response
I updated to latest version and install @typeschema/zod resolved my problem, thank you for your time and sorry for this dump issue
Glad to hear that. Out of curiosity, did you install next-safe-action@next
or next-safe-action
(stable version) when you experienced the issue described here? Because upcoming version 7 (next
branch) is a complete rewrite of the library and requires the installation of a TypeSchema adapter along with the validation lib, while version 6 requires just the validation lib to be installed. So it's expected that the two versions are incompatible with each other.