Issue
How do I solve this typescript error?
I'm getting error in the below line.
const self = this;
I'm getting error in the terminal like:
error Unexpected aliasing of 'this' to local variable @typescript-eslint/no-this-alias
Please find the code below:
notifyOwner(req, metadata, callback) {
const currentUserId = req.session.identity.individual.userName;
const docId = metadata.docId;
let message = this.templates.selfRemoval;
const self = this;
const targetUserId = metadata.ownerId;
const paperTitle = metadata.title.replace(/<(.|\n)*?>/g, '');
const nonOwnerRole = metadata.userRole;
message = message.replace(/\[CollaboratorName\]/g, req.session.identity.individual.firstName + ' ' + req.session.identity.individual.lastName);
message = message.replace(/\[NonOwnerRole\]/g, (nonOwnerRole === 'author') ? 'collaborator' : 'reviewer');
message = message.replace(/\[PaperTitle\]/g, paperTitle);
const eventData = {
message: message,
objectType: 'manuscript',
objectId: docId
};
self.createEvent(currentUserId, targetUserId, eventData, (err, result) => {
if (result) {
const userActivityService = new UserActivityService();
userActivityService.broadcastRefreshUserEvents(eventData['objectId'], { userId: targetUserId });
}
callback(null, JSON.stringify({ notified: true }));
});
}
Solution
This warning usually exists to get script-writers to utilize arrow functions instead of declaring new variables. For example, this:
let that = this;
someFn(function(arg) {
return that.foo = arg;
});
can be simplified to
someFn(arg => this.foo = arg);
But in your case, you're not even using the reassigned value in any other functions - you're just referencing it directly lower in the code, which makes the assignment completely superfluous.
Just remove your
const self = this;
and replace
self.createEvent(
with
this.createEvent(
Answered By - CertainPerformance
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.