I am working on a node app that is transpiled from typescript es6 to javascript es6. I am using inversify to inject class dependencies into the appropriate classes. When I try to access the member variables using the this operator I am getting the following error: "TypeError: Cannot read property 'organizationMemberRepository' of undefined". I noticed I began to receive this error after moving to the arrow function and removing the "that = this" logic and I am running node in a docker container. Here is the transpiled javascript file:
"use strict";
let OrganizationMemberService = class OrganizationMemberService {
constructor(organizationRepository, organizationMemberRepository, authorizationService) {
this.authenticateUser = (userName, password) => {
return new Promise(function (resolve, reject) {
console.log('about to check if user exists.....');
this.organizationMemberRepository.findMemberByUserName(userName)
.then(function (organizationMember) {
if (organizationMember) {
organizationMember.comparePassword(password)
.then(function (same) {
if (same) {
let returnedObj = JSON.parse(JSON.stringify(organizationMember));
resolve(returnedObj);
}
else {
reject(new genericerror_1.GenericError("You username/password combination is incorrect."));
}
})
.catch(function (err) {
reject(err);
});
}
else {
reject(new genericerror_1.GenericError("You username/password combination is incorrect."));
}
});
});
};
this.organizationRepository = organizationRepository;
this.organizationMemberRepository = organizationMemberRepository;
this.authorizationService = authorizationService;
}
};
OrganizationMemberService = __decorate([
inversify_1.injectable(),
__param(0, inversify_1.inject(types_1.TYPES.IOrganizationRepository)), __param(1, inversify_1.inject(types_1.TYPES.IOrganizationMemberRepository)), __param(2, inversify_1.inject(types_1.TYPES.IAuthorizationService)),
__metadata("design:paramtypes", [Object, Object, Object])
], OrganizationMemberService);
exports.OrganizationMemberService = OrganizationMemberService;
I thought that es6 arrow operator was suppose to solve the issue of not being able to properly access the this operator issue?