TypeScript express router.use() Argument type does not match parameters in WebStorm

Viewed 737

I'm currently dealing with a strange issue using WebStorm (2017.1.3, which is the latest as of now, May 2017).

While I code in TypeScript, and use Router of Express.js, WebStorm keeps me telling 'Argument types do not match parameters' in the following usage of API.

import * as express from 'express';
import {IRouter, NextFunction, Router} from "express-serve-static-core";

let router: Router = express.Router();

// works
router.get("/", () => {}); 

// complaining
router.use("/", (req, res, next) => {}); 

// complaining
router.use("/", (req: express.Response, res: express.Response, next: NextFunction) => {});

I can't figure out why WebStorm keeps me saying that, when I see that VSCode does see the exact same code as having no problem at all.

In fact this code gets compiled flawlessly with tsc, and I know I can suppress type mismatch complaining in WebStorm. It is rather I'd just want to know why this happens.

For your information, type definitions for express.js looks as following

interface IRouter extends RequestHandler {
  // ... 
  use: IRouterHandler<this> & IRouterMatcher<this>;
}

interface IRouterHandler<T> {
  (...handlers: RequestHandler[]): T;
  (...handlers: RequestHandlerParams[]): T;
} 

interface IRouterMatcher<T> {
  (path: PathParams, ...handlers: RequestHandler[]): T;
  (path: PathParams, ...handlers: RequestHandlerParams[]): T;
}

// ...   

Has anyone ever seen a similar issue? or do I miss something?

0 Answers
Related