I just upgraded the Prisma version from 4 to 5.22 and noticed that my IDE no longer recognizes some typedefs I was using.
I used to create a Typedef file to use the Prisma types in JSdoc.
- Prisma version: 5.22
- NodeJs 20
- Prisma provider -> prisma-client-js
- Previews -> prismaSchemaFolder
The import was the following:
@typedef {import('@prisma/client').posts } posts
@typedef {import('@prisma/client').PrismaClient['posts']} postsModel
/** @typedef posts */
let posts;
/** @typedef postsModel */
let postsModel;
module.exports = {
posts,
postsModel
}
And by returning the methods with the JSdoc I could hover over the variables.
Now, the IDE shows the returned types as follows:
{} extends {omit: infer LocalOmit} ? ApplyOmit<UnwrapPayload<{default: Prisma.$postsPayload<$Extensions.DefaultArgs>}>["default"], PatchFlat<LocalOmit, ExtractGlobalOmit<{}, Uncapitalize<Prisma.$postsPayload<$Extensions.DefaultArgs>["name"]>>>> : ApplyOmit<UnwrapPayload<{default: Prisma.$postsPayload<$Extensions.DefaultArgs>}>["default"], ExtractGlobalOmit<{}, Uncapitalize<Prisma.$postsPayload<$Extensions.DefaultArgs>["name"]>>>
Is there a way to fix the jsdoc, and return the objects as:
/**
* return all active posts
* @return {Promise<posts[]>}
*/
async fingAllActivePosts() {
return prisma.posts.findMany({
where: {
isActive: true
}
})
}
Thanks for the help 🥲