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.dev
mac.dev16mo 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
mid16mo 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.dev
mac.dev16mo ago
oh hmmm
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
mac.dev
mac.dev16mo ago
If it’s an input, it should error if something other than that enum is passed
mid
mid16mo ago
@.mac @yashkarthik Thank its working, there seems to something wrong with vscode, so after restart I am getting red squiggly underline
mac.dev
mac.dev16mo ago
Could be a TS server error But good to hear, just @ me if you need any more help with zod