Title says it all. I don’t see how this.authService could possibly be undefined after this.authService = new AuthService() in the constructor (or something incredibly close). The base class uses a base class of GenericApiService – why I have to use the const and pass to super before assignment.
export class AuthController extends CrudController<any> {
authService: AuthService;
constructor(app: Express) {
const authService = new AuthService(database.db!);
super('auth', app, authService);
this.authService = authService;
}
registerUser(req: Request, res: Response, next: NextFunction) {
// TS2532: Object is possibly undefined
this.authService.createUser(orgId, req.body)
.then((doc) => {
return res.status(201).json(doc);
})
}