@dfinity/zod-schemas
Version:
A collection of reusable Zod schemas and validators for common data patterns in ICP applications
35 lines (34 loc) • 1.23 kB
TypeScript
import type { z } from "zod";
/** @see {@link Option} */
export declare const inferOptionSchema: <T extends z.ZodType>(schema: T) => z.ZodOptional<T>;
/** @see {@link Nullable} */
export declare const inferNullishSchema: <T extends z.ZodType>(schema: T) => z.ZodOptional<z.ZodNullable<T>>;
/** @see {@link Nullish} */
export declare const inferNullableSchema: <T extends z.ZodType>(schema: T) => z.ZodNullable<T>;
/**
* Represents a value that may be `undefined`.
*
* @template T - The type of the wrapped value.
*
* @example
* type MaybeString = Option<string>; // string | undefined
*/
export type Option<T> = z.infer<ReturnType<typeof inferOptionSchema<z.ZodType<T>>>>;
/**
* Represents a value that may be `null`.
*
* @template T - The type of the wrapped value.
*
* @example
* type MaybeString = Nullable<string>; // string | null
*/
export type Nullable<T> = z.infer<ReturnType<typeof inferNullableSchema<z.ZodType<T>>>>;
/**
* Represents a value that may be `null` or `undefined`.
*
* @template T - The type of the wrapped value.
*
* @example
* type MaybeString = Nullish<string>; // string | null | undefined
*/
export type Nullish<T> = z.infer<ReturnType<typeof inferNullishSchema<z.ZodType<T>>>>;