Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express app.get function gives "Argument types do not match parameters" error

The following code...

app.get('/basic', (req, res) => {
    res.send({message: 'hello'})
})

generates a message Argument types do not match parameters in WebStorm 2016.2.4

Argument types do not match parameters

The relevant dependencies section in my package.json is:

"dependencies": {
  "@types/body-parser": "0.0.32",
  "@types/express": "^4.0.33",
  "@types/lodash": "^4.14.34",
  "@types/node": "^6.0.38",
  "body-parser": "1.15.1",
  "dotenv": "2.0.0",
  "express": "4.13.4",
  "lodash": "^4.13.1",
  "typescript": "^2.0.3"
},

When I remove the @types/express package, WebStorm no longer gives the error message, but the TypeScript compiler gives a error TS2307: Cannot find module 'express' message.

Is there a way to configure this differently or is WebStorm just playing catch-up with TypeScript 2?

like image 924
Andy Fleming Avatar asked Oct 25 '16 05:10

Andy Fleming


1 Answers

Had the same issue. Problem is I installed the typings from dt/express via typings install dt~express and when I looked at the type definition of .get() at the express/index.ts file, there was a mismatch:

get: {(name: string): any;} & IRouterMatcher<this>;

This was not what I wanted, and I instead did a typings install express to get the type definitions from npm/express.

My typings.json file looks like this:

{
"dependencies": {
    "express": "registry:npm/express#4.14.0+20160925001530"
  },
...
}
like image 110
Amy Ho Avatar answered Oct 26 '22 23:10

Amy Ho