question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Client is incompatible with TypeScript 4.8

See original GitHub issue

Bug description

When trying to build prisma-using project with TS 4.8, following errors are thrown:


node_modules/.prisma/client/index.d.ts:1144:45 - error TS2344: Type 'S["include"][P]' does not satisfy the constraint 'boolean | UserArgs | null | undefined'.
  Type 'S["include"]["author"]' is not assignable to type 'boolean | UserArgs | null | undefined'.
    Type 'S["include"]["author"]' is not assignable to type 'boolean | UserArgs | null | undefined'.
      Type 'S["include"]["author"]' is not assignable to type 'UserArgs'.
        Type 'S["include"]["author"]' is not assignable to type 'UserArgs'.
          Type 'S["include"][P]' is not assignable to type 'UserArgs'.
            Type 'S["include"]["author"]' is not assignable to type 'UserArgs'.
              Type 'S["include"]["author"]' is not assignable to type 'UserArgs'.

1144         P extends 'author' ? UserGetPayload<S['include'][P]> :  never
                                                 ~~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:1175:18 - error TS2344: Type 'GlobalRejectSettings' does not satisfy the constraint 'RejectOnNotFound | RejectPerOperation | undefined'.
  Type 'GlobalRejectSettings' is not assignable to type 'RejectPerOperation'.

1175     ): HasReject<GlobalRejectSettings, LocalRejectSettings, 'findUnique', 'Post'> extends True ? CheckSelect<T, Prisma__PostClient<Post>, Prisma__PostClient<PostGetPayload<T>>> : CheckSelect<T, Prisma__PostClient<Post | null >, Prisma__PostClient<PostGetPayload<T> | null >>
                      ~~~~~~~~~~~~~~~~~~~~

  node_modules/.prisma/client/index.d.ts:1161:33
    1161   export interface PostDelegate<GlobalRejectSettings> {
                                         ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectPerOperation` constraint.
  node_modules/.prisma/client/index.d.ts:1161:33
    1161   export interface PostDelegate<GlobalRejectSettings> {
                                         ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectOnNotFound | RejectPerOperation | undefined` constraint.

node_modules/.prisma/client/index.d.ts:1192:18 - error TS2344: Type 'GlobalRejectSettings' does not satisfy the constraint 'RejectOnNotFound | RejectPerOperation | undefined'.

1192     ): HasReject<GlobalRejectSettings, LocalRejectSettings, 'findFirst', 'Post'> extends True ? CheckSelect<T, Prisma__PostClient<Post>, Prisma__PostClient<PostGetPayload<T>>> : CheckSelect<T, Prisma__PostClient<Post | null >, Prisma__PostClient<PostGetPayload<T> | null >>
                      ~~~~~~~~~~~~~~~~~~~~

  node_modules/.prisma/client/index.d.ts:1161:33
    1161   export interface PostDelegate<GlobalRejectSettings> {
                                         ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectOnNotFound | RejectPerOperation | undefined` constraint.

node_modules/.prisma/client/index.d.ts:2119:18 - error TS2344: Type 'GlobalRejectSettings' does not satisfy the constraint 'RejectOnNotFound | RejectPerOperation | undefined'.
  Type 'GlobalRejectSettings' is not assignable to type 'RejectPerOperation'.

2119     ): HasReject<GlobalRejectSettings, LocalRejectSettings, 'findUnique', 'Profile'> extends True ? CheckSelect<T, Prisma__ProfileClient<Profile>, Prisma__ProfileClient<ProfileGetPayload<T>>> : CheckSelect<T, Prisma__ProfileClient<Profile | null >, Prisma__ProfileClient<ProfileGetPayload<T> | null >>
                      ~~~~~~~~~~~~~~~~~~~~

  node_modules/.prisma/client/index.d.ts:2105:36
    2105   export interface ProfileDelegate<GlobalRejectSettings> {
                                            ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectPerOperation` constraint.
  node_modules/.prisma/client/index.d.ts:2105:36
    2105   export interface ProfileDelegate<GlobalRejectSettings> {
                                            ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectOnNotFound | RejectPerOperation | undefined` constraint.

node_modules/.prisma/client/index.d.ts:2136:18 - error TS2344: Type 'GlobalRejectSettings' does not satisfy the constraint 'RejectOnNotFound | RejectPerOperation | undefined'.

2136     ): HasReject<GlobalRejectSettings, LocalRejectSettings, 'findFirst', 'Profile'> extends True ? CheckSelect<T, Prisma__ProfileClient<Profile>, Prisma__ProfileClient<ProfileGetPayload<T>>> : CheckSelect<T, Prisma__ProfileClient<Profile | null >, Prisma__ProfileClient<ProfileGetPayload<T> | null >>
                      ~~~~~~~~~~~~~~~~~~~~

  node_modules/.prisma/client/index.d.ts:2105:36
    2105   export interface ProfileDelegate<GlobalRejectSettings> {
                                            ~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends RejectOnNotFound | RejectPerOperation | undefined` constraint.

node_modules/.prisma/client/index.d.ts:3032:52 - error TS2344: Type 'S["include"][P]' does not satisfy the constraint 'boolean | PostArgs | null | undefined'.
  Type 'S["include"]["posts"]' is not assignable to type 'boolean | PostArgs | null | undefined'.
    Type 'S["include"]["posts"]' is not assignable to type 'boolean | PostArgs | null | undefined'.
      Type 'S["include"]["posts"]' is not assignable to type 'PostArgs'.
        Type 'S["include"]["posts"]' is not assignable to type 'PostArgs'.
          Type 'S["include"][P]' is not assignable to type 'PostArgs'.
            Type 'S["include"]["posts"]' is not assignable to type 'PostArgs'.
              Type 'S["include"]["posts"]' is not assignable to type 'PostArgs'.

3032         P extends 'posts' ? Array < PostGetPayload<S['include'][P]>>  :
                                                        ~~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:3033:49 - error TS2344: Type 'S["include"][P]' does not satisfy the constraint 'boolean | ProfileArgs | null | undefined'.
  Type 'S["include"]["profile"]' is not assignable to type 'boolean | ProfileArgs | null | undefined'.
    Type 'S["include"]["profile"]' is not assignable to type 'boolean | ProfileArgs | null | undefined'.
      Type 'S["include"]["profile"]' is not assignable to type 'ProfileArgs'.
        Type 'S["include"]["profile"]' is not assignable to type 'ProfileArgs'.
          Type 'S["include"][P]' is not assignable to type 'ProfileArgs'.
            Type 'S["include"]["profile"]' is not assignable to type 'ProfileArgs'.
              Type 'S["include"]["profile"]' is not assignable to type 'ProfileArgs'.

3033         P extends 'profile' ? ProfileGetPayload<S['include'][P]> | null :
                                                     ~~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:3034:60 - error TS2344: Type 'S["include"][P]' does not satisfy the constraint 'boolean | UserCountOutputTypeArgs | null | undefined'.
  Type 'S["include"]["_count"]' is not assignable to type 'boolean | UserCountOutputTypeArgs | null | undefined'.
    Type 'S["include"]["_count"]' is not assignable to type 'boolean | UserCountOutputTypeArgs | null | undefined'.

3034         P extends '_count' ? UserCountOutputTypeGetPayload<S['include'][P]> :  never
                                                     ~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:3041:60 - error TS2344: Type 'S["select"][P]' does not satisfy the constraint 'boolean | UserCountOutputTypeArgs | null | undefined'.
  Type 'S["select"]["_count"]' is not assignable to type 'boolean | UserCountOutputTypeArgs | null | undefined'.
    Type 'S["select"]["_count"]' is not assignable to type 'boolean | UserCountOutputTypeArgs | null | undefined'.

3041         P extends '_count' ? UserCountOutputTypeGetPayload<S['select'][P]> :  P extends keyof User ? User[P] : never
                                                                ~~~~~~~~~~~~~~

node_modules/.prisma/client/index.d.ts:3067:18 - error TS2344: Type 'GlobalRejectSettings' does not satisfy the constraint 'RejectOnNotFound | RejectPerOperation | undefined'.
  Type 'GlobalRejectSettings' is not assignable to type 'RejectPerOperation'.

How to reproduce

Try running tsc on a Prisma project with TypeScript 4.8

Expected behavior

tsc successfully compiles project

Prisma information

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

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

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

model Profile {
  id     Int     @id @default(autoincrement())
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int     @unique
}

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

Repository:

import type { PrismaClient, User } from '@prisma/client'

export type CreateUserRow = Omit<User, 'id'>

export class UserRepository {
  private readonly prisma: PrismaClient

  constructor(prisma: PrismaClient) {
    this.prisma = prisma
  }

  async getUser(id: number): Promise<User | null> {
    const user = await this.prisma.user.findUnique({
      where: {
        id,
      },
    })

    return user
  }

  async createUser(user: CreateUserRow): Promise<User> {
    const createdUser = await this.prisma.user.create({
      data: user,
    })
    return createdUser
  }
}

Environment & setup

TypeScript 4.8.2

Prisma Version

Prisma 4.2.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:12
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
millspcommented, Sep 1, 2022

Hey @kibertoad, yes we are going to publish this fix in the upcoming 4.3.1 patch release (within a few hours).

6reactions
janpiocommented, Sep 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma schema API (Reference)
This example shows how to configure Prisma Client to run on Ubuntu 19.04 (disco) based on the table above. generator client {.
Read more >
prisma type 'number' is not assignable to type 'never' - You.com
I'm having an issue with this strange typescript error stating that type number is ... prisma/prismaPrisma Client is incompatible with TypeScript 4.8#15041.
Read more >
@prisma/client - NPM Package Overview - Socket - Socket.dev
Prisma Client is an auto-generated, type-safe and modern JavaScript/TypeScript ORM for Node.js that's ... Prisma Client is incompatible with TypeScript 4.8 ...
Read more >
Prisma 4.4.0 Release - GitClear
fix(client): typescript 4.8 (#15072). Authored September 1, 2022 ... test(client): mongo query conflict #14001 (#15327).
Read more >
Build a FullStack tRPC CRUD App with TypeScript 2022
js, Express, Prisma, and SQLite. The tRPC API will be in a server folder and the tRPC client will be in a client...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found