zod-tutorial
zod-tutorial copied to clipboard
Cleaner solution of exercise 14
It works by using generic types.
const genericFetch = <T>(url: string, schema: z.ZodSchema<T>) => {
return fetch(url)
.then((res) => res.json())
.then((result) => schema.parse(result));
};