Inversifyjs: inversify-express-utils decorator type declarations throwing errors

Created on 14 Oct 2017  路  1Comment  路  Source: inversify/InversifyJS

Current Behavior


Currently, the decorators exported via the inversify-express-utils package throw an error similar to the following:

screenshot 2017-10-14 08 26 05

The TypeScript compiler throws the error:

error TS1241: Unable to resolve signature of method decorator when called as an expression.

Expected Behavior


Use of the decorators from the package should not throw an error when applied to a controller class method.

Steps to Reproduce (for bugs)


  1. Use TypeScript v2.5.3 or higher.
  2. Create a controller class, following the documentation given in the README of the inversify-express-utils repo
  3. Apply an httpGet, httpPost etc. decorator to a controller class method
  4. The TypeScript transpiler should throw an error.

Most helpful comment

@Josh-ES
The @httpPut function is looking for an express.RequestHandler as its second input. This is used as express middleware.
the type signature of express.RequestHandler is
(req: Request, res: Response, next: NextFunction): any;

the value that you are passing is not a function it is the return value of passport.authenticate

the way that I handle this is to have a separate middleware function

function authenticationMiddleware(req: Request, res: Response, next: NextFunction) {
    passport.authenticate(....);
}

@httpPost("/", authenticationMiddleware)
...

>All comments

@Josh-ES
The @httpPut function is looking for an express.RequestHandler as its second input. This is used as express middleware.
the type signature of express.RequestHandler is
(req: Request, res: Response, next: NextFunction): any;

the value that you are passing is not a function it is the return value of passport.authenticate

the way that I handle this is to have a separate middleware function

function authenticationMiddleware(req: Request, res: Response, next: NextFunction) {
    passport.authenticate(....);
}

@httpPost("/", authenticationMiddleware)
...
Was this page helpful?
0 / 5 - 0 ratings