UNPKG

@stacksjs/dtsx

Version:

A modern, fast .d.ts generation tool, powered by Bun.

114 lines (113 loc) 4.45 kB
/** * Enable clean default collection for the next type inference pass. * Must be called before inferNarrowType when you need a @defaultValue. */ export declare function enableCleanDefaultCollection(): void; /** * Consume the computed clean default (also disables collection). * Returns null if no clean default was computed. */ export declare function consumeCleanDefault(): string | null; /** * Infer and narrow types from values * @param inUnion - When true, widens number/boolean literals to their base types (used in array union contexts) * @param _depth - Internal recursion depth counter (do not set manually) */ export declare function inferNarrowType(value: unknown, isConst?: boolean, inUnion?: boolean, _depth?: number): string; /** * Infer and narrow types from values in union context (for arrays) * Widens number/boolean literals to base types unless const */ export declare function inferNarrowTypeInUnion(value: unknown, isConst?: boolean, _depth?: number): string; /** * Infer the public return type of a function body without building a TypeScript AST. * * This is intentionally used only by the semantic generation path. Isolated * declarations remain annotation-first and never scan implementation bodies. */ export declare function inferFunctionBodyReturnType(body: string, isAsync?: boolean, parameters?: string): string; /** * Infer array type from array literal */ export declare function inferArrayType(value: string, isConst: boolean, _depth?: number): string; /** * Parse array elements handling nested structures */ export declare function parseArrayElements(content: string): string[]; /** * Infer object type from object literal */ export declare function inferObjectType(value: string, isConst: boolean, _depth?: number): string; /** * Clean parameter defaults from function parameters */ export declare function cleanParameterDefaults(params: string): string; /** * Find matching bracket for nested structures */ export declare function findMatchingBracket(str: string, start: number, openChar: string, closeChar: string): number; /** * Infer function type from function expression */ export declare function inferFunctionType(value: string, inUnion?: boolean, _depth?: number, isConst?: boolean): string; /** * Check if a type annotation is a generic/broad type that should be replaced with narrow inference */ export declare function isGenericType(typeAnnotation: string): boolean; /** * Extract type from 'satisfies' operator * e.g., "{ port: 3000 } satisfies { port: number }" returns "{ port: number }" */ export declare function extractSatisfiesType(value: string): string | null; /** * Infer mapped type from type expression * Handles patterns like { [K in keyof T]: V } */ export declare function inferMappedType(typeStr: string): string | null; /** * Infer conditional type from type expression * Handles patterns like T extends U ? X : Y */ export declare function inferConditionalType(typeStr: string): string | null; /** * Infer template literal type from type expression * Handles patterns like `${string}-${number}` */ export declare function inferTemplateLiteralTypeAdvanced(typeStr: string): string | null; /** * Infer infer keyword usage in conditional types * Handles patterns like T extends (infer U)[] ? U : never */ export declare function extractInferTypes(typeStr: string): string[]; /** * Check if a type uses advanced TypeScript features */ export declare function isComplexType(_typeStr: string): boolean; /** * Simplify complex type for declaration output * Returns simplified version if too complex */ export declare function simplifyComplexType(typeStr: string, maxDepth?: number): string; /** * Parse utility type and extract its parameters * Handles Partial<T>, Required<T>, Pick<T, K>, Omit<T, K>, etc. */ export declare function parseUtilityType(typeStr: string): { name: string, params: string[] } | null; /** * Parse type parameters from a comma-separated string * Handles nested types properly */ export declare function parseTypeParameters(paramsStr: string): string[]; /** * Infer keyof type */ export declare function inferKeyofType(typeStr: string): string | null; /** * Infer typeof type */ export declare function inferTypeofType(typeStr: string): string | null; /** * Check if type is an indexed access type * e.g., T[K], Person['name'] */ export declare function isIndexedAccessType(typeStr: string): boolean;