swc/bundler/tests/.cache/untrusted/7ad45e3ce32425e430c885596a280ca963e8daf6.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

39 lines
1.1 KiB
TypeScript

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