mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 04:32:01 +03:00
41 lines
1.1 KiB
TypeScript
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,
|
|
});
|
|
};
|
|
}
|