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

Prisma Client is incompatible with TypeScript 4.8 #15041

Closed
kibertoad opened this issue Aug 27, 2022 · 14 comments · Fixed by #15072
Closed

Prisma Client is incompatible with TypeScript 4.8 #15041

kibertoad opened this issue Aug 27, 2022 · 14 comments · Fixed by #15072
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: prisma-client
Milestone

Comments

@kibertoad
Copy link

kibertoad commented Aug 27, 2022

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

@kibertoad kibertoad added the kind/bug A reported bug. label Aug 27, 2022
@yw662
Copy link

yw662 commented Aug 27, 2022

I have the same issue, and same errors from TS.

@DoginUwU
Copy link

DoginUwU commented Aug 28, 2022

For now, the only way I found to temporarily circumvent this was to use tsc-silent

"build": "tsc-silent --suppress @node_modules/.prisma/",

@yw662
Copy link

yw662 commented Aug 28, 2022

Downgrading TS to 4.7.4 and it will compile.

@danstarns danstarns added team/client Issue for team Client. tech/typescript Issue for tech TypeScript. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 30, 2022
@millsp millsp linked a pull request Aug 30, 2022 that will close this issue
@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 31, 2022
@Jolg42
Copy link
Member

Jolg42 commented Aug 31, 2022

Hi!
So we have a PR almost ready to be merged, it didn't make it to the 4.3.0 release yesterday.
We'll keep you updated when it's solved and in which version 👍🏼
In the meantime, keep TS < 4.8.

@Jolg42 Jolg42 changed the title Incompatible with TypeScript 4.8 Prisma Client is incompatible with TypeScript 4.8 Aug 31, 2022
@janpio janpio added this to the 4.4.0 milestone Aug 31, 2022
@kibertoad
Copy link
Author

@janpio Any chance to backport it as a semver minor for 4.3.0? September 28 is a long time to wait for people wanting to update TS.

@millsp
Copy link
Member

millsp commented 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).

@janpio
Copy link
Member

janpio commented Sep 1, 2022

Aaaand it's out: https://github.com/prisma/prisma/releases/tag/4.3.1

@capaj
Copy link

capaj commented Sep 2, 2022

this patch release 🤩

@millsp millsp self-assigned this Sep 19, 2022
@EyuelMathewos
Copy link

EyuelMathewos commented Oct 18, 2022

Found 68 errors in 4 files.

Errors Files
58 node_modules/.prisma/client/index.d.ts:1408
2 node_modules/@casl/ability/dist/types/matchers/conditions.d.ts:31
4 node_modules/@casl/prisma/dist/types/createAbilityFactory.d.ts:3
4 node_modules/@casl/prisma/dist/types/index.d.ts:7
Solution
Update Prisma dependency Libraries
npm i @prisma/client@4.4.0
npm i @casl/prisma@1.3.1
npm i @casl/ability@6.3.1
change the version to current libraries release

@ameshkin
Copy link

I am still having issues no matter what version of tsc I use. I've tried different versions of prisma as well.

@millsp
Copy link
Member

millsp commented Apr 20, 2023

Hey @ameshkin can you please open a new issue with some reproduction details? Is it npx tsc not working or is it just the editor, and if it is just in the editor did you check which ts version is in use?

@ameshkin
Copy link

Thank you for your reply. I was able to generate my prisma files to a custom folder, and then take out certain things, and change them. I changed userId to any and now it works. But there does seem to be a bug. The error comes up when I do tsc and blitz build.

It does appear that making any changes to userId or adding username to sessions breaks things.

@millsp
Copy link
Member

millsp commented Apr 21, 2023

That definitely sounds like a bug we will need to fix. Could you please open an issue and fill in the few details that we will need? Thanks you :)

@ameshkin
Copy link

That definitely sounds like a bug we will need to fix. Could you please open an issue and fill in the few details that we will need? Thanks you :)

here you go

#18866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: prisma-client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants