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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
pantharshit00commented, May 14, 2021

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?

2reactions
janpiocommented, 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data model (Reference) - Prisma
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >
Advanced type safety (Reference) - Prisma
Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated...
Read more >
Operating against partial structures of your model types - Prisma
Solution. As a solution, you can customize the generated model type using Prisma Client's helper types. The User type only contains the model's...
Read more >
Prisma Client API (Reference)
Lets you filter out duplicate rows by a specific field - for example, return only distinct Post titles. where, UserWhereInput, No, Wraps all...
Read more >
Data modeling with Prisma
Only Prisma Client : Application models in the Prisma schema are generated based on the introspection of your database schema. Data modeling happens ......
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