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

Typings in Prisma client only work for the first model in the schema #7014

Closed
tgrander opened this issue May 10, 2021 · 10 comments
Closed

Typings in Prisma client only work for the first model in the schema #7014

tgrander opened this issue May 10, 2021 · 10 comments
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client

Comments

@tgrander
Copy link

Bug description

Typings in Prisma client only work for the CRUD operations of the first model in node_modules/.prisma/client/index.d.ts.

The typings for the first model in the schema work fine. i.e. prisma.user.createMany() are auto completed with TS as I type. Hovering over createMany brings me to the typed definition in prisma client index.d.ts file.

The same is not true for all other models in the schema. i.e. prisma.property.createMany stops auto completing after .property and hovering over createMany displays type any.

If I go to node_modules/.prisma/client/index.d.ts I see that Prisma.PropertyDelegate has TS error of node_modules/.prisma/client/index".Prisma' has no exported member 'PropertyDelegate'.

Screen Shot 2021-05-10 at 11 13 01 AM

However, PropertyDelegate DOES exist in the file. The code will run successfully but I get none of the benefits of using TS with Prisma client.

Why would all XDelegate types after the first model appear to TS as not existing?

How to reproduce

I created a repo to reproduce the error

  1. Go to https://github.com/tgrander/prisma-heroku-ts
  2. Download repo
  3. Run npm install
  4. Try to use prisma client for the post model, i.e.prisma.post.createMany - it will not work
  5. Try to use prisma client for the user model, i.e.prisma.user.createMany - it will work because it is first model in schema

Expected behavior

I expect prisma client typings to work for all models - not just the first model in the schema.

Prisma information

Schema

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

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

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

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

Queries

Typings work and autocomplete for model

await prisma.user.deleteMany({
      where: {
        email: "jane@prisma.io",
      },
    });

Typings DO NOT work or autocomplete for model

await prisma.post.deleteMany({
      where: {
        author: {
          email: "jane@prisma.io",
        },
      },
    });

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: tried on 14.6 and 16.0
  • Prisma version: prisma 2.22, @prisma/client 2.22
@tgrander tgrander added the kind/bug A reported bug. label May 10, 2021
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client labels May 11, 2021
@janpio
Copy link
Member

janpio commented May 11, 2021

Ok, that is really weird. I know this sounds stupid, but have your fully restarted your VSCode and possibly computer? The language server sometimes is a bit stubborn...

@tgrander
Copy link
Author

Hi @janpio, thanks so much for taking the time to get back to me. It is weird! I upgraded and quit VSCode, restarted computer, deleted node_modules, npm installed and ran npx prisma generate... but the error persists. Have not been able to find any other issues or questions online about this particular problem, which makes me believe it may in fact be my machine. Such a strange and impeding error to have... any other ideas?

@janpio
Copy link
Member

janpio commented May 12, 2021

Not yet, but someone will soon try to use your reproduction and see if it happens for them as well.

@tgrander
Copy link
Author

@janpio I tried it on a different machine and the problem persisted. Seems that it is not my local machine after all. The repos I tried were the prisma example repos for graphql-express and heroku deployment. Same exact problem with both repos on both of my machines: only the first model in the schema can make use of the Prisma client typings. All subsequent models are untyped with the same error described in my original issue.

@pantharshit00
Copy link
Contributor

I am unable to reproduce this:
image

Can you please check the version of global typescript compiler installation if any that you have in your system and whether vscode is using that or not?

@tgrander
Copy link
Author

WOW. Thank you for pointing out the obvious @pantharshit00!!! Problem solved.

@pantharshit00
Copy link
Contributor

Ah, I'm glad that solved the issue, Thanks!

@janpio
Copy link
Member

janpio commented May 18, 2021

Can we do anything to catch this @pantharshit00? Either in our tooling or VSCode?

@janpio janpio reopened this May 22, 2021
@pantharshit00
Copy link
Contributor

There is already an issue about this: #5728

It will block the generator process when it detects user is using the wrong TS version .

@netojose
Copy link

Probably you're using Docker, and inside container, the generated types aren't present. You can fix this mapping the directory node_modules/.prisma to volume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client
Projects
None yet
Development

No branches or pull requests

4 participants