UNPKG

zod-to-x

Version:

Multi language types generation from Zod schemas.

97 lines (96 loc) 4.65 kB
import { z, ZodEnum, ZodNumber, ZodObject, ZodType } from "zod/v4"; export type { ZodArray, ZodType, ZodIntersection, ZodObject, ZodEnum, ZodDiscriminatedUnion, ZodUnion, ZodLiteral, } from "zod/v4"; export type ZodAnyUnionType = z.ZodUnion<any> | z.ZodDiscriminatedUnion<any>; type ZodNumberConstraints = { min?: number; max?: number; isInt: boolean; }; export declare enum ZodFirstPartyTypeKind { ZodAny = "any", ZodString = "string", ZodNumber = "number", ZodBigInt = "bigint", ZodLiteral = "literal", ZodBoolean = "boolean", ZodDate = "date", ZodEnum = "enum", ZodUnion = "union", ZodIntersection = "intersection", ZodObject = "object", ZodLazy = "lazy", ZodRecord = "record", ZodMap = "map", ZodSet = "set", ZodArray = "array", ZodTuple = "tuple", ZodOptional = "optional", ZodNullable = "nullable", ZodDefault = "default", ZodPromise = "promise" } /** * Zod's type is checked insted of instanceof to resolve Bun incomatibilities. */ export declare class ZodHelpers { static isZodType(i: ZodType): boolean; static isZodAny(i: ZodType): i is z.ZodAny; static isZodString(i: ZodType): i is z.ZodString; static isZodNumber(i: ZodType): i is z.ZodNumber; static isZodBigInt(i: ZodType): i is z.ZodBigInt; static isZodLiteral(i: ZodType): i is z.ZodLiteral<any>; static isZodBoolean(i: ZodType): i is z.ZodBoolean; static isZodDate(i: ZodType): i is z.ZodDate; static isZodEnum(i: ZodType): i is ZodEnum<any>; static isZodUnion(i: ZodType): i is z.ZodUnion<any>; static isZodDiscriminatedUnion(i: ZodType): i is z.ZodDiscriminatedUnion; static isZodIntersection(i: ZodType): i is z.ZodIntersection<any, any>; static isZodObject(i: ZodType): i is z.ZodObject<any>; static isZodLazy(i: ZodType): i is z.ZodLazy<any>; static isZodRecord(i: ZodType): i is z.ZodRecord<any, any>; static isZodMap(i: ZodType): i is z.ZodMap<any, any>; static isZodArray(i: ZodType): i is z.ZodArray<any>; static isZodSet(i: ZodType): i is z.ZodSet<any>; static isZodTuple(i: ZodType): i is z.ZodTuple<any>; static isZodOptional(i: ZodType): i is z.ZodOptional<any>; static isZodNullable(i: ZodType): i is z.ZodNullable<any>; static isZodDefault(i: ZodType): i is z.ZodDefault<any>; static isZodPromise<T extends ZodType>(i: ZodType): i is z.ZodPromise<T>; static isZodAnyUnionType(i: ZodType): i is z.ZodUnion<any> | z.ZodDiscriminatedUnion<readonly z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>[], string>; static isZodAnyNumberType(i: ZodType): i is z.ZodNumber | z.ZodBigInt; static isZodAnyMapType(i: ZodType): i is z.ZodRecord<any, any> | z.ZodMap<any, any>; /** * Complex types that shall always be transpiled, which output would be a type, or alias if * redefined using layered modeling. * @param zodType * @returns */ static isTranspilerableZodType(zodType: string | ZodType): boolean; /** * Primitive types that can only be transpiled if defined using layered modeling, which output * would be a type alias. * @param zodType * @param onlyArray Array types are always transpiled as alias in layered modeling. * @returns */ static isTranspilerableAliasedZodType(zodType: string | ZodType, onlyArray?: boolean): boolean; static cloneZod(i: ZodType): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>; /** * Zod2X generics are represented as Promise<"TypeName">. * Ex: z.promise(z.literal("K")) will be transpiled to Template<K> */ static isZod2XGeneric(i: ZodType): boolean; static createZodObject(properties: Map<string, ZodType>): ZodObject<any>; static getZodNumberConstraints(i: ZodNumber | z.ZodBigInt): ZodNumberConstraints; } export declare function createGenericType(name: string): any; /** * Use generic types defined in a generic ZodObject by replacing them with the actual child types. * It preserves the zod2x metadata including the genericTypes array which will be moved to the * new type during layer modeling metadata assignment. * @param genObj ZodObject with generic types. * @param childrens Record of child types to replace generics. * @returns The extended ZodObject with replaced generic types. */ export declare function useGenericType(genObj: ZodObject<any>, childrens: Record<string, ZodType>, skipLazy: true): ZodObject<any>; export declare function useGenericType(genObj: ZodObject<any>, childrens: Record<string, ZodType>, skipLazy?: false): z.ZodLazy<ZodObject<any>>;