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

Type error when using Omit a required filed with relational schema #187

Open
palprabhat opened this issue Sep 7, 2023 · 1 comment
Open

Comments

@palprabhat
Copy link

palprabhat commented Sep 7, 2023

Description of issue

I am getting type error when using omit feature on a schema that has relational fields.

Dependencies

"@prisma/client": "4.16.2"
"zod": "3.21.1"
"zod-prisma-type": "2.5.6"
"typescript": "5.0.2"

Also tried with

"@prisma/client": "5.2.0"
"zod": "3.21.1"
"zod-prisma-type": "2.7.9"
"typescript": "5.0.2"

Code

generator client {
    provider = "prisma-client-js"
}

generator zod {
    provider = "zod-prisma-types"
}

datasource db {
    provider     = "mysql"
    url          = env("DATABASE_URL")
    relationMode = "prisma"
}

model Tenant {
    tenantID        String   @id @unique(map: "Tenant_ID") @default(uuid())
    tenantName      String   @unique
    createdAt       DateTime @default(now())
    updatedAt       DateTime @updatedAt
}

model Category {
    /// @zod.custom.omit([input, model])
    tenantID         String
    categoryID       String   @id @unique(map: "Category_ID") @default(uuid())
    categoryName     String
    createdAt        DateTime @default(now())
    updatedAt        DateTime @updatedAt

    items Item[]
}


model Item {
    /// @zod.custom.omit([input, model])
    tenantID     String
    itemID       String   @id @unique(map: "Item_ID") @default(uuid())
    itemName     String
    createdAt    DateTime @default(now())
    updatedAt    DateTime @updatedAt
    
    Category Category? @relation(fields: [categoryID], references: [categoryID])
    categoryID   String

    @@index([categoryID], name: "fk_category_Item_categoryID_1")
}

Error from typescript

Getting error on this generated code

export const ItemCreateManyCategoryInputEnvelopeSchema: z.ZodType<Prisma.ItemCreateManyCategoryInputEnvelope> = z.object({
  data: z.union([ z.lazy(() => ItemCreateManyCategoryInputSchema),z.lazy(() => ItemCreateManyCategoryInputSchema).array() ]),
  skipDuplicates: z.boolean().optional()
}).strict();

Error

Type 'ZodObject<{ data: ZodUnion<[ZodLazy<ZodType<Omit<ItemCreateManyCategoryInput, "tenantID">, ZodTypeDef, Omit<ItemCreateManyCategoryInput, "tenantID">>>, ZodArray<...>]>; skipDuplicates: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<ItemCreateManyCategoryInputEnvelope, ZodTypeDef, ItemCreateManyCategoryInputEnvelope>'.
  The types of '_type.data' are incompatible between these types.
    Type 'Omit<ItemCreateManyCategoryInput, "tenantID"> | Omit<ItemCreateManyCategoryInput, "tenantID">[]' is not assignable to type 'Enumerable<ItemCreateManyCategoryInput>'.
      Type 'Omit<ItemCreateManyCategoryInput, "tenantID">' is not assignable to type 'Enumerable<ItemCreateManyCategoryInput>'.
        Property 'tenantID' is missing in type 'Omit<ItemCreateManyCategoryInput, "tenantID">' but required in type 'ItemCreateManyCategoryInput'.typescript(2322)
index.d.ts(4632, 5): 'tenantID' is declared here.
const ItemCreateManyCategoryInputEnvelopeSchema: z.ZodType<Prisma.ItemCreateManyCategoryInputEnvelope, z.ZodTypeDef, Prisma.ItemCreateManyCategoryInputEnvelope>

Link to codesandbox

@Darkbound
Copy link

I am having the same issue, practically almost everything that I can do with @z yields TS errors making the rich comments unusable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants