shelving
Version:
Toolkit for using data in JavaScript.
16 lines (15 loc) • 691 B
TypeScript
import type { Schema, SchemaOptions } from "./Schema.js";
import { ThroughSchema } from "./ThroughSchema.js";
/** Allowed options for `OptionalSchema` */
export interface OptionalSchemaOptions<T> extends SchemaOptions {
readonly source: Schema<T>;
readonly value?: T | null;
}
/** Validate a value of a specific type or `null`. */
export declare class OptionalSchema<T> extends ThroughSchema<T | null> {
readonly value: T | null;
constructor({ value, ...options }: OptionalSchemaOptions<T>);
validate(unsafeValue?: unknown): T | null;
}
/** Create a new optional schema from a source schema. */
export declare const OPTIONAL: <T>(source: Schema<T>) => OptionalSchema<T>;