omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type error in the StringFilter.schema

fcaride opened this issue · comments

Bug description

I just generated all the stuff with the "withZod" flag and th StringFilter.schema.ts file resulted like this:

const Schema: z.ZodType<Prisma.StringFilter> = z
  .object({
    equals: z.string().optional(),
    in: z.union([z.string().array(), z.string()]).optional(),
    notIn: z.union([z.string().array(), z.string()]).optional(),
    lt: z.string().optional(),
    lte: z.string().optional(),
    gt: z.string().optional(),
    gte: z.string().optional(),
    contains: z.string().optional(),
    startsWith: z.string().optional(),
    endsWith: z.string().optional(),
    not: z
      .union([z.string(), z.lazy(() => NestedStringFilterObjectSchema)])
      .optional(),
  })
  .strict();

export const StringFilterObjectSchema = Schema;

But its getting this error:
Type 'ZodObject<{ equals: ZodOptional<ZodString>; in: ZodOptional<ZodUnion<[ZodArray<ZodString, "many">, ZodString]>>; ... 8 more ...; not: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<StringFilter<never>, ZodTypeDef, StringFilter<never>>'. The types of '_type.in' are incompatible between these types. Type 'string | string[] | undefined' is not assignable to type 'string[] | undefined'. Type 'string' is not assignable to type 'string[]'.ts(2322)

If i change the lines of in and notIn to this it works fine: z.string().array().optional()

How to reproduce

Generate the prisma files of any Module.

"prisma-trpc-generator": "^1.4.1", "@prisma/client": "^5.1.1", "@trpc/client": "^10.34.0",

Expected behavior

To no have any type error

Prisma information

generator trpc {
    provider                 = "prisma-trpc-generator"
    withMiddleware           = "../src/server/api/trpcMiddleware"
    withZod                  = true
    withShield               = false
    contextPath              = "../src/server/api/trpc"
    trpcOptionsPath          = "../src/server/api/trpc"
    showModelNameInProcedure = false
    generateModelActions     = "create,delete,deleteMany,findMany,update,updateMany"
    isGenerateInclude        = true
}

model Example {
    id       String     @id @unique @default(cuid())
    name     String     @unique
}

Environment & setup

"prisma-trpc-generator": "^1.4.1",
"@prisma/client": "^5.1.1",
"@trpc/client": "^10.34.0",

Prisma Version

5.1.1

I have similar issues on a few types, (date and field realted), and I think that's because we are using Prisma V5.X which is not supported by this library atm