Skip to content

express.d.ts simple usage broken in latest bits #11875

Closed
@billti

Description

@billti

A basic Express 4 sample has errors with the latest bits. It appears to be a regression in TypeScript 2.1.

Below is how far I’ve managed to reduce the code into a standalone repro before heading home (from the definition currently in @types/express).

If I compile with the current bits in the “release-2.0.5” branch there is no error. This is specific to what is currently in “release-2.1”.

severity: 'Error'
message: 'Argument of type '(err: any, req: Response, res: NextFunction, next: any) => void' is not assignable to parameter of type 'PathParams'.
  Type '(err: any, req: Response, res: NextFunction, next: any) => void' is not assignable to type '(string | RegExp)[]'.
    Property 'push' is missing in type '(err: any, req: Response, res: NextFunction, next: any) => void'.'
var app: myApp;

app.use((err: any, req, res, next) => { return; }); // <--- error on this call to 'use'


interface myApp {
    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;
    }

    type PathParams = string | RegExp | (string | RegExp)[];
    type RequestHandlerParams = RequestHandler | ErrorRequestHandler | (RequestHandler | ErrorRequestHandler)[];

    interface RequestHandler {
        (req: Request, res: Response, next: NextFunction): any;
    }

    interface ErrorRequestHandler {
        (err: any, req: Request, res: Response, next: NextFunction): any;
    }

    interface Request {
        method: string;
    }

    interface Response {
        statusCode: number;
    }

    interface NextFunction {
        (err?: any): void;
    }

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions