Skip to content

Documenting Typing the Extended PrismaClient #129

@NGimbal

Description

@NGimbal

I've been running into an issue where the VSCode Typescript errors with errors like the following:

Excessive stack depth comparing types...
This expression is not callable....

After searching and consulting with various AI oracles I realized the issue could be solved by removing the prisma-field-encryption extension. This Github issue was a hint, although the discussion is from when clientExtensions were a preview feature.

prisma/prisma#17236

The solution seems to be the following:

import { PrismaClient } from '@prisma/client'
import { fieldEncryptionExtension } from 'prisma-field-encryption'
import { type PrismaClientExtends } from '@prisma/client/extension'
import type * as runtime from '@prisma/client/runtime/library'

// Define the extended client type using Prisma's extension type system
type ExtendedClient = PrismaClient & PrismaClientExtends<runtime.Types.Extensions.DefaultArgs>

const globalClient = new PrismaClient()

export const client = globalClient.$extends(
  // This is a function, don't forget to call it:
  fieldEncryptionExtension()
) as ExtendedClient

export type { ExtendedClient as PrismaClient }

Does this fix make sense? It is working nicely for me. If so I'd like to open a PR to add this to the Readme. 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions