Search code examples
node.jstypescriptexpresstypescript2.0tsc

Change res.getHeader() to res.get()


I have the following code

const compress = require('compression');

export const handleCompression = compress({
  filter: function (req: express.Request, res: express.Response) {
    return (/json|text|javascript|css|font|svg/).test(res.getHeader('Content-Type'));
  },
  level: 9
});

I get this warning from TypeScript:

enter image description here

Would it be correct to change the call to:

res.get('Content-Type')

?


Solution

  • Yes or better: req.header('Content-Type').

    See footer here.