I am following this guide https://vercel.com/guides/nextjs-prisma-postgres to create a full stack app. Typescript is throwing an error in this snippet of code:
import { PrismaClient } from '@prisma/client';
let prisma: PrismaClient;
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
}
export default prisma;
TypeScript is throwing a ts7017 on the global.prisma:
Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
Can someone help me understand this and how to fix? I set 'strict' to false in the tsconfig for the meantime and that supressed the issue for the meantime, though I'm sure having it off defeats the purpose of TS.
global.prismais declared? If you don't have access to its declaration, have you tried casting it withglobal.prisma as PrismaClient?import prisma from '../lib/prisma';PrismaClientin this way because otherwise the DB connection limit gets exhausted in development due to Next.js' hot reloading. Here's our docs page about this: prisma.io/docs/support/help-articles/… I'm checking back with some of our TypeScript engineers to see how this issue can be solved.