UNPKG

@dfinity/zod-schemas

Version:

A collection of reusable Zod schemas and validators for common data patterns in ICP applications

20 lines (19 loc) 696 B
import * as z from "zod"; /** @see {@link Result} */ export declare const inferResultSchema: <T extends z.ZodType>(schema: T) => z.ZodDiscriminatedUnion<[z.ZodObject<{ status: z.ZodLiteral<"success">; result: T; }, z.core.$strict>, z.ZodObject<{ status: z.ZodLiteral<"error">; err: z.ZodOptional<z.ZodUnknown>; }, z.core.$strict>]>; /** * Represents a result type with a success or error state. * * @template T - The type of the success `result` value. * * @example * type StringResult = Result<string>; * // { status: "success"; result: string } | { status: "error"; err?: unknown } */ export type Result<T> = z.infer<ReturnType<typeof inferResultSchema<z.ZodType<T>>>>;