Documenting Typing the Extended PrismaClient

Open Beginner friendly
#129 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
75/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Domain
documentation

Research direction

The issue is about adding a TypeScript typing example to the README. Look at the existing README file to see where the usage examples are placed. The provided code snippet shows how to type an extended PrismaClient with the field encryption extension. Verify the snippet works by checking the current extension API in the source code, then update the documentation accordingly.

Written by the indexing model from the issue text.

Description

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.

https://github.com/prisma/prisma/issues/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. 🙏

Dominant language
TypeScript
Stars
307
Forks
40
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 47ng/prisma-field-encryption

All issues in 47ng/prisma-field-encryption

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.