Skip to content

Commit

Permalink
test(types): use type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Feb 12, 2023
1 parent 7a3c6d4 commit 3fd88a1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('http-proxy-middleware TypeScript Types', () => {
expect(options).toBeDefined();
});

it('should get implicit express types from express server', () => {
it('should get contextual types from express server', () => {
const app = express();
app.use(
middleware({
Expand All @@ -153,7 +153,11 @@ describe('http-proxy-middleware TypeScript Types', () => {
on: {
error(error, req, res, target) {
req.params;
(res as express.Response).status(200).send('OK');

// https://www.typescriptlang.org/docs/handbook/2/narrowing.html
if (res instanceof http.ServerResponse) {
res.status(200).send('OK');
}
},
proxyReq(proxyReq, req, res, options) {
req.params;
Expand Down Expand Up @@ -205,7 +209,11 @@ describe('http-proxy-middleware TypeScript Types', () => {
on: {
error(error, req, res, target) {
req.myRequestParams;
(res as MyResponse).myResponseParams;

// https://www.typescriptlang.org/docs/handbook/2/narrowing.html
if (res instanceof http.ServerResponse) {
res.myResponseParams;
}
},
proxyReq(proxyReq, req, res, options) {
req.myRequestParams;
Expand Down

0 comments on commit 3fd88a1

Please sign in to comment.