MCPcopy
hub / github.com/colinhacks/zod / ZodNullable

Class ZodNullable

packages/zod/src/v3/types.ts:4525–4549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4523export type ZodNullableType<T extends ZodTypeAny> = ZodNullable<T>;
4524
4525export class ZodNullable<T extends ZodTypeAny> extends ZodType<
4526 T["_output"] | null,
4527 ZodNullableDef<T>,
4528 T["_input"] | null
4529> {
4530 _parse(input: ParseInput): ParseReturnType<this["_output"]> {
4531 const parsedType = this._getType(input);
4532 if (parsedType === ZodParsedType.null) {
4533 return OK(null);
4534 }
4535 return this._def.innerType._parse(input);
4536 }
4537
4538 unwrap() {
4539 return this._def.innerType;
4540 }
4541
4542 static create = <Inner extends ZodTypeAny>(type: Inner, params?: RawCreateParams): ZodNullable<Inner> => {
4543 return new ZodNullable({
4544 innerType: type,
4545 typeName: ZodFirstPartyTypeKind.ZodNullable,
4546 ...processCreateParams(params),
4547 }) as any;
4548 };
4549}
4550
4551////////////////////////////////////////////
4552////////////////////////////////////////////

Callers

nothing calls this directly

Calls 1

processCreateParamsFunction · 0.85

Tested by

no test coverage detected