Skip to content

Commit 82ad7c1

Browse files
authored
test(types): contextual types (#946)
1 parent a703969 commit 82ad7c1

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

test/types.spec.ts

+50-50
Original file line numberDiff line numberDiff line change
@@ -193,56 +193,56 @@ describe('http-proxy-middleware TypeScript Types', () => {
193193
expect(app).toBeDefined();
194194
});
195195

196-
// FIXME: contextual types should work with express path middleware
197-
// it('should get contextual types from express server', () => {
198-
// const app = express();
199-
// app.use(
200-
// '/',
201-
// middleware({
202-
// router: (req) => req.params,
203-
// pathFilter: (pathname, req) => !!req.params,
204-
// on: {
205-
// error(error, req, res, target) {
206-
// req.params;
207-
208-
// // https://www.typescriptlang.org/docs/handbook/2/narrowing.html
209-
// if (res instanceof http.ServerResponse) {
210-
// res.status(200).send('OK');
211-
// }
212-
// },
213-
// proxyReq(proxyReq, req, res, options) {
214-
// req.params;
215-
// res.status(200).send('OK');
216-
// },
217-
// proxyReqWs(proxyReq, req, socket, options, head) {
218-
// req.params;
219-
// },
220-
// proxyRes(proxyRes, req, res) {
221-
// req.params;
222-
// res.status(200).send('OK');
223-
// },
224-
// close(proxyRes, proxySocket, proxyHead) {
225-
// proxyRes.params;
226-
// },
227-
// start(req, res, target) {
228-
// req.params;
229-
// res.status(200).send('OK');
230-
// },
231-
// end(req, res, proxyRes) {
232-
// req.params;
233-
// res.status(200).send('OK');
234-
// proxyRes.params;
235-
// },
236-
// econnreset(error, req, res, target) {
237-
// req.params;
238-
// res.status(200).send('OK');
239-
// },
240-
// },
241-
// })
242-
// );
243-
244-
// expect(app).toBeDefined();
245-
// });
196+
it('should get contextual types from express server', () => {
197+
const app = express();
198+
app.use(
199+
'/',
200+
// FIXME: contextual types should work with express path middleware (without providing explicit types)
201+
middleware<express.Request, express.Response>({
202+
router: (req) => req.params,
203+
pathFilter: (pathname, req) => !!req.params,
204+
on: {
205+
error(error, req, res, target) {
206+
req.params;
207+
208+
// https://www.typescriptlang.org/docs/handbook/2/narrowing.html
209+
if (res instanceof http.ServerResponse) {
210+
res.status(200).send('OK');
211+
}
212+
},
213+
proxyReq(proxyReq, req, res, options) {
214+
req.params;
215+
res.status(200).send('OK');
216+
},
217+
proxyReqWs(proxyReq, req, socket, options, head) {
218+
req.params;
219+
},
220+
proxyRes(proxyRes, req, res) {
221+
req.params;
222+
res.status(200).send('OK');
223+
},
224+
close(proxyRes, proxySocket, proxyHead) {
225+
proxyRes.params;
226+
},
227+
start(req, res, target) {
228+
req.params;
229+
res.status(200).send('OK');
230+
},
231+
end(req, res, proxyRes) {
232+
req.params;
233+
res.status(200).send('OK');
234+
proxyRes.params;
235+
},
236+
econnreset(error, req, res, target) {
237+
req.params;
238+
res.status(200).send('OK');
239+
},
240+
},
241+
}),
242+
);
243+
244+
expect(app).toBeDefined();
245+
});
246246

247247
it('should work with explicit generic custom req & res types', () => {
248248
interface MyRequest extends http.IncomingMessage {

0 commit comments

Comments
 (0)