Cannot infer type of prisma accelerate extended client

I'm trying to use prisma accelerate so that I can use the caching functionality, but i'm running into an issue where typescript cannot actually infer the type of the resulting prisma client. This is the code i'm using to instantiate the client:
export function createPrismaClient() {
return new PrismaClient().$extends(withAccelerate());
}
export type ExtendedPrismaClient = ReturnType<typeof createPrismaClient>;
export function createPrismaClient() {
return new PrismaClient().$extends(withAccelerate());
}
export type ExtendedPrismaClient = ReturnType<typeof createPrismaClient>;
This is the error that I'm getting:
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
5 Replies
Prisma AI Help
Prisma AI Help•4w ago
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
thedappercamper
thedappercamperOP•4w ago
for additional context, these are the current versions of prisma i'm using:
"prisma": "6.2.1"
"@prisma/client": "6.2.1"
"@prisma/extension-accelerate": "2.0.2"
"@prisma/instrumentation": "6.18.0"
"prisma": "6.2.1"
"@prisma/client": "6.2.1"
"@prisma/extension-accelerate": "2.0.2"
"@prisma/instrumentation": "6.18.0"
for now i've manually constructed an artificial type that injects the cacheStrategy parameter and other $accelerate functions appropriately. this is definitely not ideal...but seems to work for now. would love some insight here if there's a better solution:
import $Extensions = runtime.Types.Extensions;
// Build the extended client type
type BasePrismaClient = PrismaClient<
Prisma.PrismaClientOptions,
never,
$Extensions.DefaultArgs
>;

// Use Prisma's runtime Result type to compute return types based on args
// This preserves the conditional return types for include/select/omit

// Type-safe wrapper that preserves Prisma's conditional return types
type ModelDelegateWithCache<TDelegate> = {
[K in keyof TDelegate]: K extends "findUnique"
? <T extends Prisma.Args<TDelegate, "findUnique"> & PrismaCacheStrategy>(
args: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findUnique">>
: K extends "findUniqueOrThrow"
? <
T extends Prisma.Args<TDelegate, "findUniqueOrThrow"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "findUniqueOrThrow">
>
: K extends "findFirst"
? <T extends Prisma.Args<TDelegate, "findFirst"> & PrismaCacheStrategy>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findFirst">>
: K extends "findFirstOrThrow"
? <
T extends Prisma.Args<TDelegate, "findFirstOrThrow"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "findFirstOrThrow">
>
: K extends "findMany"
? <
T extends Prisma.Args<TDelegate, "findMany"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findMany">>
: K extends "count"
? <
T extends Prisma.Args<TDelegate, "count"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "count">>
: K extends "aggregate"
? <
T extends Prisma.Args<TDelegate, "aggregate"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "aggregate">
>
: K extends "groupBy"
? <
T extends Prisma.Args<TDelegate, "groupBy"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "groupBy">
>
: TDelegate[K];
};

export type ExtendedPrismaClient = Omit<
BasePrismaClient,
"$extends" | Prisma.ModelName
> & {
[K in Prisma.ModelName]: ModelDelegateWithCache<BasePrismaClient[K]>;
} & {
$accelerate: {
invalidate: (input: AccelerateInvalidateInput) => Promise<{
requestId: string;
}>;
invalidateAll: () => Promise<{
requestId: string;
}>;
};
};
import $Extensions = runtime.Types.Extensions;
// Build the extended client type
type BasePrismaClient = PrismaClient<
Prisma.PrismaClientOptions,
never,
$Extensions.DefaultArgs
>;

// Use Prisma's runtime Result type to compute return types based on args
// This preserves the conditional return types for include/select/omit

// Type-safe wrapper that preserves Prisma's conditional return types
type ModelDelegateWithCache<TDelegate> = {
[K in keyof TDelegate]: K extends "findUnique"
? <T extends Prisma.Args<TDelegate, "findUnique"> & PrismaCacheStrategy>(
args: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findUnique">>
: K extends "findUniqueOrThrow"
? <
T extends Prisma.Args<TDelegate, "findUniqueOrThrow"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "findUniqueOrThrow">
>
: K extends "findFirst"
? <T extends Prisma.Args<TDelegate, "findFirst"> & PrismaCacheStrategy>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findFirst">>
: K extends "findFirstOrThrow"
? <
T extends Prisma.Args<TDelegate, "findFirstOrThrow"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "findFirstOrThrow">
>
: K extends "findMany"
? <
T extends Prisma.Args<TDelegate, "findMany"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "findMany">>
: K extends "count"
? <
T extends Prisma.Args<TDelegate, "count"> &
PrismaCacheStrategy,
>(
args?: T,
) => Prisma.PrismaPromise<Prisma.Result<TDelegate, T, "count">>
: K extends "aggregate"
? <
T extends Prisma.Args<TDelegate, "aggregate"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "aggregate">
>
: K extends "groupBy"
? <
T extends Prisma.Args<TDelegate, "groupBy"> &
PrismaCacheStrategy,
>(
args: T,
) => Prisma.PrismaPromise<
Prisma.Result<TDelegate, T, "groupBy">
>
: TDelegate[K];
};

export type ExtendedPrismaClient = Omit<
BasePrismaClient,
"$extends" | Prisma.ModelName
> & {
[K in Prisma.ModelName]: ModelDelegateWithCache<BasePrismaClient[K]>;
} & {
$accelerate: {
invalidate: (input: AccelerateInvalidateInput) => Promise<{
requestId: string;
}>;
invalidateAll: () => Promise<{
requestId: string;
}>;
};
};
Aman
Aman•4w ago
You are on a super old version of prisma Try 6.18.0? 🤔
thedappercamper
thedappercamperOP•4w ago
unfortunately didn't help. still getting the same typing inference error
Nurul
Nurul•4w ago
We had a new update go out version 6.19.0, can you try if that fixed it by any chance? If not, would it be possible to provide a minimal reproduction so that our ORM team can have a look?

Did you find this page helpful?