SolvedDefinitelyTyped [@types/express] Latest types throw Property 'headers', 'body', 'query' does not exist on type 'Request<any>'

duro
293

If you know how to fix the issue, make a pull request instead.

My builds are throwing the following errors after upgrades to latest version of the @types/express package:

Property 'headers' does not exist on type 'Request<any>'

Property 'query' does not exist on type 'Request<any>'

Property 'body' does not exist on type 'Request<any>'

We have changed nothing on our end. I also noticed that my TS environment, when I open up the index.d.ts of @types/express shows the following errors:

`express-serve-static-core` has no exported member 'ParamsDictionary'

`express-serve-static-core` has no exported member 'Params'

`express-serve-static-core` has no exported member 'Params'

Some kind of breaking change seems to have been introduced, and I cannot seem to find any guidelines on how to address.

34 Answers

✔️Accepted Answer

I solved this issue with yarn by doing:

$ rm -f yarn.lock
$ yarn cache clean
$ yarn

Have nice day!

Other Answers:

This is still an issue, installed the latest express / express-serve-static-core types. The problem is when extending the Request interface.

interface ExampleRequest extends Request {
  example: any
}
// No overload matches this call...
router.use('/api', async function (req:ExampleRequest, res, next) { ... }

Same. Running rm -rf node modules && rm package-lock.json && npm update fixed that issue, but now all of my req.params are forced into strings.

Definitely a breaking change and not a patch.

I had the same issue and can confirm updating @types/express-serve-static-core to 4.16.11 fixed the issue for me. My package-lock file had locked the version to 4.16.7 previously.

This simplest package.json works with yarn install , but not work with npm install or yarn install --flat .

{
    "dependencies": {
        "@types/express": "4.17.2",
        "@types/express-serve-static-core": "4.16.8",
        "@types/node": "^12.12.5",
        "typescript": "^3.6.4"
    }
}

Because @types/express 4.17.2 (#38887) is depend on @types/express-serve-static-core 4.16.9 (#37718) to provide generic usage.

More Issues: