typescript and trpc data validation

another noob question from me, but trying to figure out typescript. So if I have a piece of code like this in my router:
export const coinRouter = router({
getCoin: publicProcedure
.input(z.object({ name: z.any()}))
.query(async ({ input }) => {
const coin = await fetch(`https://api.coingecko.com/api/v3/coins/${input.name}`).then(res =>
res.json());
return coin
}),
});
export const coinRouter = router({
getCoin: publicProcedure
.input(z.object({ name: z.any()}))
.query(async ({ input }) => {
const coin = await fetch(`https://api.coingecko.com/api/v3/coins/${input.name}`).then(res =>
res.json());
return coin
}),
});
and the data from this api url is really long , how should I go about typing it? I am not using the whole of the data, so is there a way to pick in trpc router only the data that I'm interested in?
3 Replies
Leonidas
Leonidas3y ago
Use typescripts Pick type helper
noctate
noctate3y ago
But do you mean I should use it to create data from all the objects inside this json? because there are a lot, also not sure how Pick works (newbie typescripter here) to type data* sry
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server