mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 09:52:57 +03:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// Loaded from https://raw.githubusercontent.com/colinhacks/zod/654680afc2ede388e71e09104eac5a0088fe3207/deno/lib/types/promise.ts
|
|
|
|
|
|
import { ZodTypes } from "../ZodTypes.ts";
|
|
import { ZodType, ZodTypeDef, ZodTypeAny } from "./base.ts";
|
|
|
|
// import { ZodUndefined } from './undefined';
|
|
// import { ZodNull } from './null';
|
|
// import { ZodUnion } from './union';
|
|
|
|
export interface ZodPromiseDef<T extends ZodTypeAny = ZodTypeAny>
|
|
extends ZodTypeDef {
|
|
t: ZodTypes.promise;
|
|
type: T;
|
|
}
|
|
|
|
export class ZodPromise<T extends ZodTypeAny> extends ZodType<
|
|
Promise<T["_output"]>,
|
|
ZodPromiseDef<T>,
|
|
Promise<T["_input"]>
|
|
> {
|
|
toJSON = () => {
|
|
return {
|
|
t: this._def.t,
|
|
type: this._def.type.toJSON(),
|
|
};
|
|
};
|
|
|
|
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
|
|
|
|
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
|
|
|
|
static create = <T extends ZodTypeAny>(schema: T): ZodPromise<T> => {
|
|
return new ZodPromise({
|
|
t: ZodTypes.promise,
|
|
type: schema,
|
|
});
|
|
};
|
|
}
|