express: Express Typings Broken in TS 2.2.x (VS Code, WebStorm, pretty much everything)

import express = require('express');
import { NextFunction } from "@types/express-serve-static-core";

const router:express.Router = express.Router();

router.get('/', (req: Request, res: Response, next: NextFunction) => {

});

export = router;

Possibly Related: https://github.com/Microsoft/TypeScript/issues/11875

Error Message:

Argument of type ‘(req: Request, res: Response, next: NextFunction) => void’ is not assignable to parameter of type ‘RequestHandlerParams’. Type ‘(req: Request, res: Response, next: NextFunction) => void’ is not assignable to type ‘(RequestHandler | ErrorRequestHandler)[]’. Property ‘push’ is missing in type ‘(req: Request, res: Response, next: NextFunction) => void’.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I’ve been using express typings with a number of projects without any problems. It seems to be me like the code in the initial post is missing 1) importing Request and Response and 2) are importing NextFunction from the wrong package.

This is what have been working for me:

// Import types
import { Request, Response, NextFunction } from 'express'

// Import express
import express = require('express')

// Create app
const app = express()

// Define route
app.get('/', (req: Request, res: Response, next: NextFunction) => {
  res.send('Hello, World!')
})

// Listen for connections
app.listen(3000, () => {
  console.log('http://localhost:3000')
})

edit: this is with npm install --save express @types/express

@blakeembrey SGTM. If we can get the ball rolling on it now, we can have a very nice reason to upgrade to 4.16 (including TSD).

@dougwilson I can contribute the typings we do have to Express.js and continue iterating if that works for you? /cc @felixfbecker

Hi @joefallon we don’t maintain any Typings, so there really is nothing we can address directly. Do you know who maintains the typings / where are they stored?