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] Generated schemas contain Typescript error #222

Closed
Flusinerd opened this issue Dec 14, 2023 · 5 comments
Closed

[BUG] Generated schemas contain Typescript error #222

Flusinerd opened this issue Dec 14, 2023 · 5 comments
Assignees
Labels
bug (unconfirmed) Could be a bug

Comments

@Flusinerd
Copy link

Flusinerd commented Dec 14, 2023

Describe the bug
After running prisma generate the generated typescript file contains typescript errors that prevent building.

Screenshots
If applicable, add screenshots to help explain your problem.
image

image

image

image

Package versions (please complete the following information):

  • zod: 3.22.4
  • prisma: 5.7.0

Additional context
My schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

generator zod {
  provider = "zod-prisma-types"
  output   = "../../../libs/models/src/lib/prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Session {
  session   String   @id
  userId    String   @db.Uuid
  expiresAt DateTime
  createdAt DateTime @default(now())
  user      User     @relation(fields: [userId], references: [id])
}

model User {
  id          String    @id @default(uuid()) @db.Uuid
  email       String    @unique
  password    String
  firstName   String
  lastName    String
  displayName String
  location    String?
  bio         String?
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
  Sessions    Session[]
}
@Flusinerd
Copy link
Author

https://github.com/Flusinerd/clouts
This is the repo url.
The generated file is in the libs/models... folder

@nordowl
Copy link
Contributor

nordowl commented Dec 14, 2023

Facing the same error using zod: 3.22.3 & prisma: 5.5.2

Types of property 'id' are incompatible.
     Type 'number | IntFieldUpdateOperationsInput | undefined' is not assignable to type 'undefined'.
           Type 'number' is not assignable to type 'undefined'.

@nordowl
Copy link
Contributor

nordowl commented Dec 15, 2023

The issue seems to be caused by zod versions higher than 3.21.1. See this issue I found.
Changing my zod version to 3.21.1 resolved the error.

@chrishoermann
Copy link
Owner

@Flusinerd @nordowl yes this is a bug in zod versions higher than 3.21.1. To support the latest version you can use the useTypeAssertions option. But be aware that this circumvents the internal type checking. I use it in my own projects without any bugs so far but it can lead to bugs in the typesystem that are hard to debug

@andrewmartin
Copy link

Just wanted to say, thank you for documenting that you have the useTypeAssertions available here. Stumbled on this thread and it helped a ton.

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

4 participants