When using TypeScript with JavaScript and Angular:
I am trying to use the throttle decorator from lodash to limit an API call while a user is navigating around the page, ensuring that it fires before they leave the site.
In my TypeScript constructor, I have
window.addEventListener('beforeunload', () => this.onUnload());
with the onUnload()
function being defined as
onUnload() {
this.thisIsTheThrottledFunction.flush;
}
However, I am encountering the error message "Property 'flush' does not exist on type '() => Promise'."
The function's .flush
method that I am attempting to access is the throttled version of another function. Despite the successful throttling of the function, I still cannot access the .flush
method. What is the best way to solve this issue?