I have the following code which calls a lodash debounce function:
@HostListener("window:scroll", [])
onWindowScroll() {
    if (myBoolean) 
       _.debounce(this.onScrollDown(), 1500, false);
    }
}
private onScrollDown() {
    console.log("onScrollDown")
}
But I'm getting this error in my console:
Argument of type 'void' is not assignable to parameter of type 'Function'.
And the following on browser:
TypeError: Expected a function
    at Function.debounce 
I'm using typescript by the way
I'm not familiar with lodash, but I think what you want is:
private debouncedOnScroll = _.debounce(() => this.onScrollDown(), 1500, {});
@HostListener("window:scroll", [])
onWindowScroll() {
    this.debouncedOnScroll();
}
private onScrollDown() {
    console.log("onScrollDown")
}
                        Thanks to JB Nizet I could solve my need this is my approach:
private projectsLoad(myParameter): void {
   // function code here...
};
private debounceProjectsLoad = _.debounce(
    (myParameter) => this.projectsLoad(myParameter),
    1500,
    true
);
public loadProjectsGroup(myParameter: string): void {
    this.debounceProjectsLoad(myParameter);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With