swc/crates/swc_bundler/tests/.cache/untrusted/1978d01125b05890423e00306e689c9eb0cf9fda.ts
2021-11-09 20:42:49 +09:00

41 lines
1.1 KiB
TypeScript

// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/lazy.ts
import { ZodTypes } from "../ZodTypes.ts";
import { input, output, ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts";
// import { ZodUndefined } from './undefined';
// import { ZodNull } from './null';
// import { ZodUnion } from './union';
export interface ZodLazyDef<T extends ZodTypeAny = ZodTypeAny>
extends ZodTypeDef {
t: ZodTypes.lazy;
getter: () => T;
}
export class ZodLazy<T extends ZodTypeAny> extends ZodType<
output<T>,
ZodLazyDef<T>,
input<T>
> {
get schema(): T {
return this._def.getter();
}
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
toJSON = () => {
throw new Error("Can't JSONify recursive structure");
};
static create = <T extends ZodTypeAny>(getter: () => T): ZodLazy<T> => {
return new ZodLazy({
t: ZodTypes.lazy,
getter: getter,
});
};
}