Tomasz Kisiel
Tomasz Kisiel
PPrisma
Created by Tomasz Kisiel on 1/6/2025 in #help-and-questions
Type of client extended with dynamic extensions
Hi! In Prisma docs they say that to get type of extended client we can use factory function and ReturnType utility as follows:
function getExtendedClient() {
return new PrismaClient().$extends({
/* extension */
})
}

type ExtendedPrismaClient = ReturnType<typeof getExtendedClient>
function getExtendedClient() {
return new PrismaClient().$extends({
/* extension */
})
}

type ExtendedPrismaClient = ReturnType<typeof getExtendedClient>
And this work fine but how I can get client type when the set of extensions is dynamic? I mean the case when extensions are provided as argument to factory function and it cannot by tell explicitly what extensions are ther?
function getExtendedClient(extensions: NeedType[] = []) { // missing type for extension
return extensions.reduce((client, extension) => client.$extends(extension), new PrismaClient());
}

type ExtendedPrismaClient = ReturnType<typeof getExtendedClient> // won't work
function getExtendedClient(extensions: NeedType[] = []) { // missing type for extension
return extensions.reduce((client, extension) => client.$extends(extension), new PrismaClient());
}

type ExtendedPrismaClient = ReturnType<typeof getExtendedClient> // won't work
Is this possible to handle such a case with Prisma and TypeScript?
6 replies