diff --git a/index.d.ts b/index.d.ts index 39d094d..4136d44 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,26 +1,35 @@ -import { IncomingMessage, ServerResponse, ClientRequest } from 'http'; -import * as Koa from 'koa'; +import type {IncomingMessage, ServerResponse, ClientRequest} from 'http'; -declare function KoaProxies(path: string | RegExp | (string | RegExp)[], options: KoaProxies.IKoaProxiesOptions): Koa.Middleware; +import type * as Koa from 'koa'; -declare namespace KoaProxies { - interface IBaseKoaProxiesOptions { - target: string; - changeOrigin?: boolean; - logs?: boolean | ((ctx: Koa.Context, target: string) => void); - agent?: any; - headers?: {[key: string]: string}; - rewrite?: (path: string) => string; - events?: { - error?: (error: any, req: IncomingMessage, res: ServerResponse) => void; - proxyReq?: (proxyReq: ClientRequest, req: IncomingMessage, res: ServerResponse) => void; - proxyRes?: (proxyRes: IncomingMessage, req: IncomingMessage, res: ServerResponse) => void; +declare module 'koa-proxies' { + function KoaProxies( + path: Array | RegExp | string, + options: KoaProxies.IKoaProxiesOptions>, + ): Koa.Middleware; + + namespace KoaProxies { + interface IBaseKoaProxiesOptions { + target: string; + changeOrigin?: boolean; + logs?: boolean | ((ctx: ContextT, target: string) => void); + agent?: unknown; + headers?: Record; + rewrite?: (path: string) => string; + events?: { + error?: (error: unknown, req: IncomingMessage, res: ServerResponse) => void; + proxyReq?: (proxyReq: ClientRequest, req: IncomingMessage, res: ServerResponse) => void; + proxyRes?: (proxyRes: IncomingMessage, req: IncomingMessage, res: ServerResponse) => void; + }; } - } - type IKoaProxiesOptionsFunc = (params: { [key: string]: string }, ctx: Koa.Context) => IBaseKoaProxiesOptions | false; + type IKoaProxiesOptionsFunc = ( + params: Record, + ctx: ContextT, + ) => IBaseKoaProxiesOptions; - type IKoaProxiesOptions = string | IBaseKoaProxiesOptions | IKoaProxiesOptionsFunc; -} + type IKoaProxiesOptions = IBaseKoaProxiesOptions | IKoaProxiesOptionsFunc | string; + } -export = KoaProxies; + export default KoaProxies; +}