Skip to content

Return type of ProxyResCallback is void, but responseInterceptor is Promise<void> #1139

@Floriferous

Description

@Floriferous

Checks

Describe the bug (be clear and concise)

I'm seeing a type mismatch when writing the following code:

createProxyMiddleware({
  on: {
    proxyReq: responseInterceptor( ... )
  }
})

The error is detected by typescript-eslint:

Promise-returning function provided to property where a void return was expected.eslint[@typescript-eslint/no-misused-promises](https://typescript-eslint.io/rules/no-misused-promises)

The types are defined as follows:

// on.proxyRes
type ProxyResCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
        proxyRes: TIncomingMessage,
        req: TIncomingMessage,
        res: TServerResponse,
    ) => void;

// responseInterceptor
export declare function responseInterceptor<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(interceptor: Interceptor<TReq, TRes>): (proxyRes: TReq, req: TReq, res: TRes) => Promise<void>;

I'm not sure if on.proxyRes should support promises, or if the returnValue of responseInterceptor should just be void.

Step-by-step reproduction instructions

-

Expected behavior (be clear and concise)

There shouldn't be a type mismatch.

How is http-proxy-middleware used in your project?

-

What http-proxy-middleware configuration are you using?

-

What OS/version and node/version are you seeing the problem?

TypeScript 5.8.3
Node 22

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions