@stacksjs/dtsx
Version:
A modern, fast .d.ts generation tool, powered by Bun.
142 lines (141 loc) • 3.74 kB
TypeScript
/**
* Get preset mappings
*/
export declare function getPresetMappings(preset: TypeMappingPreset): TypeMappingRule[];
/**
* Create a type mapper with configuration
*/
export declare function createTypeMapper(config?: TypeMappingConfig): TypeMapper;
/**
* Apply type mappings to declaration text
*/
export declare function applyTypeMappings(declarationText: string, mapper: TypeMapper, context?: Partial<TypeMappingContext>): string;
/**
* Default type mappings for common patterns
*/
export declare const defaultTypeMappings: TypeMappingRule[];
/**
* Strict mode mappings - converts unsafe types
*/
export declare const strictTypeMappings: TypeMappingRule[];
/**
* Readonly mappings - adds immutability
*/
export declare const readonlyTypeMappings: TypeMappingRule[];
/**
* Simplified mappings - reduces complexity
*/
export declare const simplifiedTypeMappings: TypeMappingRule[];
/**
* Default type mapper instance
*/
export declare const defaultTypeMapper: TypeMapper;
/**
* Strict type mapper instance
*/
export declare const strictTypeMapper: TypeMapper;
/**
* Built-in type transformers
* @defaultValue
* ```ts
* {
* makeReadonly: (type: string) => string,
* makeNullable: (type: string) => string,
* makeOptional: (type: string) => string,
* makeRequired: (type: string) => string,
* promisify: (type: string) => string,
* unpromisify: (type: string) => string,
* arrayify: (type: string) => string,
* unarrayify: (type: string) => string
* }
* ```
*/
export declare const TypeTransformers: {
/**
* Make all types readonly
*/
makeReadonly: (type: string) => string;
/**
* Make type nullable
*/
makeNullable: (type: string) => string;
/**
* Make type optional (add undefined)
*/
makeOptional: (type: string) => string;
/**
* Remove null/undefined from type
*/
makeRequired: (type: string) => string;
/**
* Wrap in Promise
*/
promisify: (type: string) => string;
/**
* Unwrap Promise
*/
unpromisify: (type: string) => string;
/**
* Convert to array type
*/
arrayify: (type: string) => string;
/**
* Unwrap array type
*/
unarrayify: (type: string) => string
};
/**
* Custom type mappings for DTS generation
* Allows users to specify type replacements and transformations
*/
/**
* Type mapping rule
*/
export declare interface TypeMappingRule {
pattern: string | RegExp
replacement: string
condition?: (context: TypeMappingContext) => boolean
global?: boolean
priority?: number
}
/**
* Context passed to type mapping functions
*/
export declare interface TypeMappingContext {
type: string
declarationName?: string
declarationKind?: string
filePath?: string
isReturnType?: boolean
isParameterType?: boolean
isPropertyType?: boolean
}
/**
* Type mapping configuration
*/
export declare interface TypeMappingConfig {
rules: TypeMappingRule[]
presets?: TypeMappingPreset[]
includeDefaults?: boolean
cacheKey?: string
}
/**
* Available type mapping presets
*/
export type TypeMappingPreset = | 'strict' // Convert 'any' to 'unknown'
| 'readonly' // Add readonly to array types
| 'nullable' // Convert undefined unions to optional
| 'branded' // Use branded types for primitives
| 'simplified' // Simplify complex utility types;
/**
* Type mapper class for applying transformations
*/
export declare class TypeMapper {
constructor(config?: TypeMappingConfig);
map(type: string, context?: Partial<TypeMappingContext>): string;
mapAll(types: string[], context?: Partial<TypeMappingContext>): string[];
addRule(rule: TypeMappingRule): void;
removeRules(pattern: string | RegExp): number;
clearCache(): void;
getRules(): readonly TypeMappingRule[];
}