/** * Type Casting Utilities * * Utility functions for safe type casting * Maintains type safety by replacing `as any` usage * * @module utils/type-casting */ import type { InternalRequest, InternalResponse, InternalSocket, InternalRouter, InternalError } from '../types/internal'; /** * Cast Request to InternalRequest * * @param req - Request object (allows any type) * @returns Object casted to InternalRequest type * * @example * ```typescript * const internalReq = asInternalRequest(req) * internalReq.params = { id: '123' } * ``` */ export declare function asInternalRequest(req: any): InternalRequest; /** * Cast Response to InternalResponse * * @param res - Response object (allows any type) * @returns Object casted to InternalResponse type * * @example * ```typescript * const internalRes = asInternalResponse(res) * internalRes.req = req * internalRes.app = app * ``` */ export declare function asInternalResponse(res: any): InternalResponse; /** * Cast Socket to InternalSocket * * @param socket - Socket object (allows any type) * @returns Object casted to InternalSocket type * * @example * ```typescript * const internalSocket = asInternalSocket(req.socket) * const encrypted = internalSocket.encrypted * const ip = internalSocket.remoteAddress * ``` */ export declare function asInternalSocket(socket: any): InternalSocket; /** * Cast Router to InternalRouter * * @param router - Router object (allows any type) * @returns Object casted to InternalRouter type * * @example * ```typescript * const internalRouter = asInternalRouter(router) * internalRouter[method](path, handler) // Dynamic method call * ``` */ export declare function asInternalRouter(router: any): InternalRouter; /** * Cast Error to InternalError * * @param error - Error object (allows any type) * @returns Object casted to InternalError type * * @example * ```typescript * const internalError = asInternalError(error) * const statusCode = internalError.statusCode || 500 * const code = internalError.code * ``` */ export declare function asInternalError(error: any): InternalError; /** * Cast any type to specific type (generic version) * * @param value - any type value * @returns Value casted to T type * * @example * ```typescript * const value = castTo(someAnyValue) * ``` */ export declare function castTo(value: any): T; /** * Add field to object (type-safe) * * @param target - Target object * @param key - Field name to add * @param value - Value to add * * @example * ```typescript * setField(req, 'params', { id: '123' }) * setField(res, 'req', req) * ``` */ export declare function setField(target: T, key: K, value: V): asserts target is T & Record; /** * Get field from object (type-safe) * * @param source - Source object * @param key - Field name to get * @returns Field value * * @example * ```typescript * const params = getField>(req, 'params') * const app = getField(res, 'app') * ``` */ export declare function getField(source: any, key: string): T | undefined; /** * Check if object has field and get it * * @param source - Source object * @param key - Field name to check * @returns Field value or undefined * * @example * ```typescript * const params = getFieldSafe>(req, 'params') * if (params) { * console.log(params.id) * } * ``` */ export declare function getFieldSafe(source: any, key: string): T | undefined; //# sourceMappingURL=type-casting.d.ts.map