I have created a class with the following implementation:
import {Request, Response, Router} from 'express';
import {IAccessTokenMiddleWare} from "./IAccessTokenMiddleWare";
class AccessTokenMiddleWare implements IAccessTokenMiddleWare {
private jwtToken: string;
constructor() {
this.jwtToken = "";
}
public init() : any {
return function (req: Request, res: Response, next: any) {
this.addJwtToReqBody(req);
}
}
private addJwtToReqBody(req) {
console.log("ADDED...")
}
}
export {AccessTokenMiddleWare}
I am initializing it in my code as shown below:
var accessTokenMiddleWare = new AccessTokenMiddleWare();
router.use(accessTokenMiddleWare.init());
However, I'm encountering an error message:
error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
Could someone guide me on resolving this error?