From e3744463a153893d84eef5600b2f792a6e9d251b Mon Sep 17 00:00:00 2001 From: Steven Chim <655241+chimurai@users.noreply.github.com> Date: Sat, 7 Feb 2026 22:01:47 +0000 Subject: [PATCH] test(types.spec.ts): add type check when req or res are 'any' --- test/types.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/types.spec.ts b/test/types.spec.ts index 6f306f9b..5c69c05a 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -182,6 +182,11 @@ describe('http-proxy-middleware TypeScript Types', () => { error(error, req, res, target) { req.params; + // @ts-expect-error: should error when request is typed as `any` + req.unknownProperty; + // @ts-expect-error: should error when response is typed as `any` + res.unknownProperty; + // https://www.typescriptlang.org/docs/handbook/2/narrowing.html if (res instanceof http.ServerResponse) { res.status(200).send('OK'); @@ -345,6 +350,11 @@ describe('http-proxy-middleware TypeScript Types', () => { proxyRes: responseInterceptor(async (buffer, proxyRes, req, res) => { req.myRequestParams; res.myResponseParams; + + // @ts-expect-error: should error when request is typed as `any` + req.unknownProperty; + // @ts-expect-error: should error when response is typed as `any` + res.unknownProperty; return buffer; }), }, @@ -371,6 +381,12 @@ describe('http-proxy-middleware TypeScript Types', () => { (proxyServer, options) => { proxyServer.on('proxyReq', (proxyReq, req, res, options) => { req.params; + + // @ts-expect-error: should error when request is typed as `any` + req.unknownProperty; + // @ts-expect-error: should error when response is typed as `any` + res.unknownProperty; + res.status(200).send('OK'); }); }, @@ -396,6 +412,12 @@ describe('http-proxy-middleware TypeScript Types', () => { responseInterceptor(async (buffer, proxyRes, req, res) => { req.params; res.status(200).send('OK'); + + // @ts-expect-error: should error when request is typed as `any` + req.unknownProperty; + // @ts-expect-error: should error when response is typed as `any` + res.unknownProperty; + return buffer; }), );