mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
// 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>;
|
|
};
|
|
}
|