YeonHoPark
07/19/2022, 1:14 AMgetUser
must return a value containing only information about the select object received as an argument. and it must be type safe !Austin
07/25/2022, 7:10 PMPrisma.UserSelect
to type the parameter to the getUser
function?
If not, could you explain your use case a little more?Vladi Stevanovic
YeonHoPark
08/01/2022, 4:41 AMPrisma.UserSelect
to type the parameter to the getUser
function?
that’s one of the things i want.
I add a bit more to the code above to explain what i want…
The getUser function receive the various prisma include
and select
object received as arguments, retrieve them, and return the object in a type safe way.
As the getUser function receives as an arguments, the prisma is searched, and the type is specified.
e.g..
1. I want the user and his posts.
const userWithPosts = await getUser({ include: { posts:true }})
// userWithPosts type
const userWithPosts: (User & {
posts: Post[];
})
2. I want the user and hi profile.
const userWithProfile = await getUser({ include: { profile:true } })
// userWithProfile type
const userWithProfile: (User & {
profile: Profile;
})
3. I want the user and his id.
const userWithIdSelect = await getUser({ select: { id:true } })
// userWithIdSelect type
const userWithPosts: {
id: string;
}
4. many other case…Vladi Stevanovic
Austin
08/09/2022, 3:26 PMconst getUser = async (select: Prisma.UserSelect) => {...}