/** * Zod type introspection utilities * * Provides version-agnostic type detection using duck typing instead of * instanceof checks, which fail across Zod v3/v4 boundaries. * * @module zod-introspection */ /** * Zod type names from _def.typeName * * These internal type names are stable across Zod v3 and v4. * Using these constants instead of instanceof checks ensures * compatibility when user's Zod version differs from library's. * * @see https://github.com/colinhacks/zod/issues/2543 */ export declare const ZodTypeNames: { readonly STRING: "ZodString"; readonly NUMBER: "ZodNumber"; readonly BOOLEAN: "ZodBoolean"; readonly ARRAY: "ZodArray"; readonly OBJECT: "ZodObject"; readonly ENUM: "ZodEnum"; readonly OPTIONAL: "ZodOptional"; readonly NULLABLE: "ZodNullable"; readonly DATE: "ZodDate"; readonly LITERAL: "ZodLiteral"; readonly UNION: "ZodUnion"; readonly INTERSECTION: "ZodIntersection"; readonly TUPLE: "ZodTuple"; readonly RECORD: "ZodRecord"; readonly MAP: "ZodMap"; readonly SET: "ZodSet"; readonly FUNCTION: "ZodFunction"; readonly LAZY: "ZodLazy"; readonly PROMISE: "ZodPromise"; readonly BRANDED: "ZodBranded"; readonly PIPELINE: "ZodPipeline"; readonly READONLY: "ZodReadonly"; readonly SYMBOL: "ZodSymbol"; readonly UNDEFINED: "ZodUndefined"; readonly NULL: "ZodNull"; readonly ANY: "ZodAny"; readonly UNKNOWN: "ZodUnknown"; readonly NEVER: "ZodNever"; readonly VOID: "ZodVoid"; readonly BIGINT: "ZodBigInt"; readonly EFFECTS: "ZodEffects"; readonly NATIVENUM: "ZodNativeEnum"; readonly DISCRIMINATED_UNION: "ZodDiscriminatedUnion"; readonly DEFAULT: "ZodDefault"; readonly CATCH: "ZodCatch"; readonly NAN: "ZodNaN"; }; /** * Type representing valid Zod type names */ export type ZodTypeName = (typeof ZodTypeNames)[keyof typeof ZodTypeNames]; /** * Get Zod type name in version-agnostic way * * Supports both Zod v3 and v4: * - Zod v3: Uses _def.typeName (e.g., 'ZodString') * - Zod v4: Uses _def.type (e.g., 'string'), converts to v3 format * * Uses duck typing instead of instanceof checks, which fail when * user's Zod version differs from library's Zod version. * * @param zodType - Zod type to introspect * @returns Type name string (e.g., 'ZodString') or undefined if not a Zod type * * @example * ```typescript * import { z } from 'zod'; * import { getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils'; * * const schema = z.string(); * const typeName = getZodTypeName(schema); * console.log(typeName); // 'ZodString' (both v3 and v4) * * if (typeName === ZodTypeNames.STRING) { * console.log('It\'s a string schema!'); * } * ``` */ export declare function getZodTypeName(zodType: unknown): string | undefined; /** * Check if Zod type matches expected type name * * Version-agnostic type checking using duck typing. * Safer than instanceof when Zod versions may differ. * * @param zodType - Zod type to check * @param typeName - Expected type name constant from ZodTypeNames * @returns True if type matches, false otherwise * * @example * ```typescript * import { z } from 'zod'; * import { isZodType, ZodTypeNames } from '@vibe-agent-toolkit/utils'; * * const schema = z.array(z.string()); * * if (isZodType(schema, ZodTypeNames.ARRAY)) { * console.log('It\'s an array schema!'); * } * ``` */ export declare function isZodType(zodType: unknown, typeName: ZodTypeName): boolean; /** * Unwrap optional/nullable Zod types to get inner type * * Recursively unwraps ZodOptional and ZodNullable to reach * the underlying type. Returns original type if not wrapped. * * @param zodType - Zod type to unwrap * @returns Unwrapped Zod type * * @example * ```typescript * import { z } from 'zod'; * import { unwrapZodType, getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils'; * * const schema = z.string().optional(); * const unwrapped = unwrapZodType(schema); * * console.log(getZodTypeName(unwrapped)); // 'ZodString' * ``` */ export declare function unwrapZodType(zodType: unknown): unknown; /** * Check if Zod type is optional (ZodOptional) * * @param zodType - Zod type to check * @returns True if type is optional */ export declare function isZodOptional(zodType: unknown): boolean; /** * Check if Zod type is nullable (ZodNullable) * * @param zodType - Zod type to check * @returns True if type is nullable */ export declare function isZodNullable(zodType: unknown): boolean; //# sourceMappingURL=zod-introspection.d.ts.map