fn.ts 321 B

1234567891011
  1. import { z } from "zod"
  2. export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
  3. const result = (input: z.infer<T>) => {
  4. const parsed = schema.parse(input)
  5. return cb(parsed)
  6. }
  7. result.force = (input: z.infer<T>) => cb(input)
  8. result.schema = schema
  9. return result
  10. }