omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TS conflict between zod + prisma in CreateOne, updateOne, upsertOne

paullyFIRE opened this issue · comments

Bug description

Hi, firstly, fantastic project, and thank you for your contributions!

With a default setup from the readme in this repo, there is a type error for the createOnePost / updateOnePost / upsertOnePost mutations in Post.router.ts - seemingly a conflict between the Zod Schemas + Prisma input types that are expected.

image

Dump of error from TS for createOnePost:

Argument of type '{ data: (PostCreateInput | PostUncheckedCreateInput) & (PostCreateInput | PostUncheckedCreateInput | undefined); }' is not assignable to parameter of type '{ select?: PostSelect | null | undefined; include?: PostInclude | null | undefined; data: (Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput); }'.
  Types of property 'data' are incompatible.
    Type '(PostCreateInput | PostUncheckedCreateInput) & (PostCreateInput | PostUncheckedCreateInput | undefined)' is not assignable to type '(Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput)'.
      Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type '(Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput)'.
        Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type 'Without<PostUncheckedCreateInput, PostCreateInput> & PostCreateInput'.
          Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type 'Without<PostUncheckedCreateInput, PostCreateInput>'.
            Types of property 'id' are incompatible.
              Type 'number | undefined' is not assignable to type 'undefined'.
                Type 'number' is not assignable to type 'undefined'.ts(2345)

This happens in my turbo-repo setup, but I made a clean project to sanity check and the same error occurs.

Let me know how I can help, if possible.

How to reproduce

  1. Create new repo following https://www.prisma.io/docs/getting-started/quickstart (basic prisma install + TS init + prisma init.)
  2. Follow TRPC quickstart https://trpc.io/docs/quickstart (installing client + server)
  3. Follow this repos quickstart (adding package + prisma models for user + post in readme, install zod)
  4. Prisma Generate
  5. Note type errors for createOne, updateOne, upsertOne actions

Expected behavior

No type errors preventing TS builds

Prisma information

// 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"
}

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

generator trpc {
  provider        = "prisma-trpc-generator"
  withZod         = true
  withMiddleware  = false
  withShield      = false
  contextPath     = "../context"
  trpcOptionsPath = "../trpcOptions"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
}

Environment & setup

  • OS: Mac OS
  • Database: SQLite
  • Node.js version: 16.14

Prisma Version

prisma                  : 4.13.0
@prisma/client          : 4.13.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a (at ../../node_modules/.pnpm/@prisma+engines@4.13.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a (at ../../node_modules/.pnpm/@prisma+engines@4.13.0/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.13.0-50.1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a
Default Engines Hash    : 1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a
Studio                  : 0.484.0