zod-tutorial icon indicating copy to clipboard operation
zod-tutorial copied to clipboard

Cleaner solution of exercise 14

Open qianzhong516 opened this issue 1 year ago • 0 comments

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));
};

qianzhong516 avatar Jun 17 '24 09:06 qianzhong516