chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

TS2322 Errors #196

Closed breagan1983 closed 8 months ago

breagan1983 commented 8 months ago

First, thank yo so much for making this library. It seems like an awesome foundation for a data model.

I've been beating my head against the wall on getting past the TS2322 errors that are supposed to be fixed by enforcing Zod v3.21.1. For whatever reason, when compiling I'm still butting up against this issue.

Is there anything you can see that I'm missing or screwing up? Thank you for any time you have to take a glance.

package.json, and verified in package-lock.json, after several goes of deleteting node_modules, package-lock.json, the generated prisma types, re-running npm install, etc package.json:

  "overrides": {
    "zod-prisma-types": {
      "zod": "3.21.1"
    }
  },

package-lock.json

    "node_modules/zod": {
      "version": "3.21.1",
      "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.1.tgz",
      "integrity": "sha512-+dTu2m6gmCbO9Ahm4ZBDapx2O6ZY9QSPXst2WXjcznPMwf2YNpn3RevLx4KkZp1OPW/ouFcoBtBzFz/LeY69oA==",
      "funding": {
        "url": "https://github.com/sponsors/colinhacks"
      }
    },
    "node_modules/zod-prisma-types": {
      "version": "2.7.13",
      "resolved": "https://registry.npmjs.org/zod-prisma-types/-/zod-prisma-types-2.7.13.tgz",
      "integrity": "sha512-HuGrm333z/7yDnJ2ZCXTJmkTREzRpOSj5koNCNQkaqm/RxbQfv2HqAMeX9DX7KeEvMiYBb6alggSNo3Z/wXbJQ==",
      "dependencies": {
        "@prisma/generator-helper": "^5.4.2",
        "code-block-writer": "^12.0.0",
        "lodash": "^4.17.21",
        "zod": "^3.21.1"
      },
      "bin": {
        "zod-prisma-types": "dist/bin.js"
      }
    },

Example error:

prisma/types/schemas/index.ts:2805:14 - error TS2322: Type 'ZodObject<{ select: ZodOptional<ZodType<AnalyzerSelect<DefaultArgs>, ZodTypeDef, AnalyzerSelect<DefaultArgs>>>; include: ZodOptional<...>; data: ZodUnion<...>; where: ZodType<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<Omit<AnalyzerUpdateArgs<DefaultArgs>, "data"> & { data: Omit<AnalyzerUpdateInput, "id"> | Omit<AnalyzerUncheckedUpdateInput, "id">; }, ZodTypeDef, Omit<...> & { ...; }>'.
  Types of property '_type' are incompatible.
    Type '{ select?: AnalyzerSelect<DefaultArgs> | undefined; include?: AnalyzerInclude<DefaultArgs> | undefined; data: Omit<...> | Omit<...>; where: Omit<...>; }' is not assignable to type 'Omit<AnalyzerUpdateArgs<DefaultArgs>, "data"> & { data: Omit<AnalyzerUpdateInput, "id"> | Omit<AnalyzerUncheckedUpdateInput, "id">; }'.
      Type '{ select?: AnalyzerSelect<DefaultArgs> | undefined; include?: AnalyzerInclude<DefaultArgs> | undefined; data: Omit<...> | Omit<...>; where: Omit<...>; }' is not assignable to type 'Omit<AnalyzerUpdateArgs<DefaultArgs>, "data">'.
        Types of property 'where' are incompatible.
          Type 'Omit<AnalyzerWhereUniqueInput, "id">' is not assignable to type 'AnalyzerWhereUniqueInput'.

2805 export const AnalyzerUpdateArgsSchema: z.ZodType<Omit<Prisma.AnalyzerUpdateArgs, "data"> & { data: z.infer<typeof AnalyzerUpdateInputSchema> | z.infer<typeof AnalyzerUncheckedUpdateInputSchema> }> = z.object({

tsconfig.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "target": "ES2018",
    "module": "CommonJS",
    "lib": ["dom", "ESNext"],
    "baseUrl": ".",
    "moduleResolution": "node",
    "outDir": "./dist",
    "rootDir": "./",
    "declaration": true,
    "declarationMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "isolatedModules": false,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "allowJs": false,
    "removeComments": true,
    "forceConsistentCasingInFileNames": false,
    "inlineSources": false,
    "allowSyntheticDefaultImports": true,
    "strict": true
  },
  "include": ["**/*.ts"],
  "exclude": ["**/node_modules", "**/*.test.ts", "**/dist", "**/*spec.ts"]
}
breagan1983 commented 8 months ago

Must be a PEBKEC issue; looks to be working now. Not sure what fixed it; played around with only generating the schema and also leveraging some of the @anatine companion libraries and something must flushed the obstruction.

Again, thanks for this library; getting this working with NestJS seems like a sweet setup!