According to https://github.com/microsoft/TypeScript/issues/6331 referencing this
in static is perfectly legal, however, using a class like:
class ZController {
static async b(req: RequestType, res: Response) {
await this.a(req);
}
static async a(req) {
console.log('here')
}
}
results in:
Error: unhandledRejection: Cannot read properties of undefined (reading 'a')
TypeError: Cannot read properties of undefined (reading 'a')
at b (/usr/src/app/controllers/z.ts:24:33)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
at xxx (/usr/src/app/middlewares/Auth.js:108:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I am running Typescript 4.4.2.
Why is this? According to my research typescript should support this.