swc/bundler/tests/.cache/untrusted/a98057429b2194ee0127cd350f8dc5d0bd3e405c.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/nullable.ts
import { ZodTypes } from "../ZodTypes.ts";
import { ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts";
export interface ZodNullableDef<T extends ZodTypeAny = ZodTypeAny>
extends ZodTypeDef {
t: ZodTypes.nullable;
innerType: T;
}
// This type allows for nullable flattening
export type ZodNullableType<
T extends ZodTypeAny
> = T extends ZodNullable<ZodTypeAny> ? T : ZodNullable<T>;
export class ZodNullable<
T extends ZodTypeAny
// Output extends T['_output'] | null = T['_output'] | null,
// Input extends T['_input'] | null = T['_input'] | null
> extends ZodType<T["_output"] | null, ZodNullableDef<T>, T["_input"] | null> {
// An nullable nullable is the original nullable
// nullable: () => ZodNullableType<this> = () => this as ZodNullableType<this>;
toJSON = () => ({
t: this._def.t,
innerType: this._def.innerType.toJSON(),
});
static create = <T extends ZodTypeAny>(type: T): ZodNullableType<T> => {
if (type instanceof ZodNullable) return type as ZodNullableType<T>;
return new ZodNullable({
t: ZodTypes.nullable,
innerType: type,
}) as ZodNullableType<T>;
};
}