TheEdoRan / next-safe-action

Type safe and validated Server Actions in your Next.js project.
https://next-safe-action.dev
MIT License
2.06k stars 32 forks source link

[BUG] Incompatible schema type with Zod #119

Closed tuankietcoderr closed 4 months ago

tuankietcoderr commented 4 months ago

Are you using the latest version of this library?

Is there an existing issue for this?

Describe the bug

I'm getting this error when using with zod

Screenshot 2024-05-09 at 20 19 24

My schema is:

Screenshot 2024-05-09 at 20 20 05

Reproduction steps

I created a module to include safeAction:

Screenshot 2024-05-09 at 20 22 35

I created a module include taxFormSchema:

Screenshot 2024-05-09 at 20 20 05

And the error occured:

Screenshot 2024-05-09 at 20 19 24

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

TheEdoRan commented 4 months ago

image

Cannot reproduce the issue on my end. Please provide a link to a public repo with a minimal reproduction of the problem so I can investigate the issue.

tuankietcoderr commented 4 months ago

I updated to latest version and install @typeschema/zod resolved my problem, thank you for your time and sorry for this dump issue

TheEdoRan commented 4 months ago

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.