Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] type error in generated InputJsonValueSchema #247

Open
jason-curtis opened this issue May 1, 2024 · 4 comments
Open

[BUG] type error in generated InputJsonValueSchema #247

jason-curtis opened this issue May 1, 2024 · 4 comments
Assignees
Labels
bug (unconfirmed) Could be a bug

Comments

@jason-curtis
Copy link

jason-curtis commented May 1, 2024

Describe the bug
a type error in generated InputJsonValueSchema

Screenshots
Running tsc:

db/generated/zod/index.ts:39:14 - error TS2322: Type 'ZodLazy<ZodUnion<[ZodString, ZodNumber, ZodBoolean, ZodObject<{ toJSON: ZodFunction<ZodTuple<[], null>, ZodAny>; }, "strip", ZodTypeAny, { ...; }, { ...; }>, ZodRecord<...>, ZodArray<...>]>>' is not assignable to type 'ZodType<InputJsonValue, ZodTypeDef, InputJsonValue>'.
  Types of property '_type' are incompatible.
    Type 'string | number | boolean | any[] | { toJSON?: (...args: unknown[]) => any; } | Record<string, any>' is not assignable to type 'InputJsonValue'.
      Type '{ toJSON?: (...args: unknown[]) => any; }' is not assignable to type 'InputJsonValue'.
        Type '{ toJSON?: (...args: unknown[]) => any; }' is not assignable to type '{ toJSON(): unknown; }'.
          Property 'toJSON' is optional in type '{ toJSON?: (...args: unknown[]) => any; }' but required in type '{ toJSON(): unknown; }'.

39 export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
                ~~~~~~~~~~~~~~~~~~~~


Found 1 error in db/generated/zod/index.ts:3

Contents of the generated inputJsonValueSchema:

export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
  z.union([
    z.string(),
    z.number(),
    z.boolean(),
    z.object({ toJSON: z.function(z.tuple([]), z.any()) }),
    z.record(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
    z.array(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
  ])
);

Package versions (please complete the following information):

  • zod:
> yarn why zod -R
└─ root-workspace-0b6124@workspace:.
  ├─ zod-prisma-types@npm:3.1.6 (via npm:^3.1.6)
  │  └─ zod@npm:3.23.5 (via npm:^3.22.4)
  └─ zod@npm:3.21.1 (via npm:3.21.1)
  • prisma:
> yarn why prisma
└─ @redwoodjs/cli@npm:7.0.6
  └─ prisma@npm:5.9.1 (via npm:5.9.1)

Additional context
Zod generator in schema.prisma file:

generator zod {
  provider                         = "zod-prisma-types"
  createOptionalDefaultValuesTypes = true
  useDefaultValidators             = false
  writeNullishInModelTypes         = true // Accept "undefined" in nullable fields
  useTypeAssertions                = true // silence typescript issues :p
}
@imprakharshukla
Copy link

I am facing this issue, are there any fixes yet?

@pengshengjie
Copy link

Me too~~~

@aktkro
Copy link

aktkro commented Sep 14, 2024

Same here.

@mwalkerwells
Copy link

My temporary work around is transforming

export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
  z.union([
    z.string(),
    z.number(),
    z.boolean(),
    z.object({ toJSON: z.function(z.tuple([]), z.any()) }),
    z.record(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
    z.array(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
  ])
);

into

export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
  z.union([
    z.string(),
    z.number(),
    z.boolean(),
    z.record(z.lazy(() => InputJsonValueSchema)),
    z.array(z.lazy(() => InputJsonValueSchema)),
  ])
);

It would be nice to have a fix though 🙏🏻.
@chrishoermann I just discovered this library and am really loving having it—thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unconfirmed) Could be a bug
Projects
None yet
Development

No branches or pull requests

6 participants