Zod with custom type

Need custom type validation in zod. help!!
type media_type = "all" | "movie" | "tv" | "person"
type media_type = "all" | "movie" | "tv" | "person"
And use something like
getTrending: publicProcedure
.input(
z.object({
media_type: z.custom() //need the media_type check here)
})
)
.query(({ input }) => {
return {
...input
};
}),
getTrending: publicProcedure
.input(
z.object({
media_type: z.custom() //need the media_type check here)
})
)
.query(({ input }) => {
return {
...input
};
}),
7 Replies
mac
mac2y ago
getTrending: publicProcedure
.input(
z.object({
media_type: z.enum(["all","movie","tv","person"])
})
)
.query(({ input }) => {
return {
...input
};
}),
getTrending: publicProcedure
.input(
z.object({
media_type: z.enum(["all","movie","tv","person"])
})
)
.query(({ input }) => {
return {
...input
};
}),
@mid something like that should work
mid
midOP2y ago
no static check but it does give me error if i pass other values(compile time check) @.mac Is there a way to do static check?
mac
mac2y ago
oh hmmm
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mac
mac2y ago
If it’s an input, it should error if something other than that enum is passed
mid
midOP2y ago
@.mac @yashkarthik Thank its working, there seems to something wrong with vscode, so after restart I am getting red squiggly underline
mac
mac2y ago
Could be a TS server error But good to hear, just @ me if you need any more help with zod
Want results from more Discord servers?
Add your server