I've been working on a method map based on a query from the Stack Overflow post linked here to assist me in dynamically calling a static method. But, I keep encountering this error message:
Avoid referencing unbound methods that could lead to unintentional scoping issues with
this
Any ideas on how to resolve this?
addCourseContentElementMethodMap = {
[CourseContentElementMethodMap.ADD_COURSE_CONTENT_ELEMENT_AUDIO]:
CourseContentElementAudioService.addCourseContentElement,
// Other mappings go here...
};
This error persists for each line listed above:
55:7 error Avoid referencing unbound methods which may cause unintentional scoping of `this` @typescript-eslint/unbound-method
57:7 error Avoid referencing unbound methods which may cause unintentional scoping of `this` @typescript-eslint/unbound-method
// More errors listed here...
The problematic methods are defined as follows:
export class CourseContentElementAudioService {
constructor(private courseContentElementService: CourseContentElementsService) {}
}
Here's an example of one of these methods:
static addCourseContentElement(
courseContents: ICourseContent[],
selectedCourseContentElementUid: string,
selectedCourseContentUid: string | undefined
): ICourseContent[] {
return CourseContentElementsService.addCourseContentElement(
courseContents,
selectedCourseContentUid,
{
uid: selectedCourseContentElementUid,
url: initialState.courseMedia.audio[0].url,
},
CourseContentElementType.AUDIO
);
}