Based on this GitHub issue, it is stated that referencing this
in a static context is allowed. However, when using a class structure like the following:
class ZController {
static async b(req: RequestType, res: Response) {
await this.a(req);
}
static async a(req) {
console.log('here')
}
}
An error occurs:
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)
The project is utilizing Typescript version 4.4.2.
This raises the question - why does TypeScript not support this feature as expected?