...">

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

The following code ...

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

generates a message Argument types do not match parametersin WebStorm 2016.2.4

Argument types do not match parameters

The corresponding dependency section in mine is package.json:

"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 delete the package @types/express, WebStorm no longer gives an error message, but the TypeScript compiler gives a message error TS2307: Cannot find module 'express'.

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

+4
source share
3 answers

EDIT: this solved itself in Webstorm v2016.3.1


, , :

import * as express from 'express'

const app : express.Application | express.Router = express()
0

. , dt/express typings install dt~express, .get() express/index.ts, :

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

, , typings install express, npm/express.

typings.json :

{
"dependencies": {
    "express": "registry:npm/express#4.14.0+20160925001530"
  },
...
}
+2

TypeScript - , , :

import * as express from "express";
...
public app: express.Application;

Do

import { NextFunction, Application, Router } from "express";
...
public app: Application;
0
source

Source: https://habr.com/ru/post/1658766/


All Articles