Skip to content

Commit

Permalink
refactor: fix debounce function typings
Browse files Browse the repository at this point in the history
  • Loading branch information
johannkor committed Dec 28, 2023
1 parent 59487ac commit dc3e8c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
* @param { number } wait Time to wait before execut the function
* @param { boolean } immediate Param to define if the function will be executed immediately
*/
const debounce = (func: (...args: any[]) => void, wait?: number, immediate?: boolean) => {
const debounce = <T, A extends any[]>(
func: (...args: A) => void,
wait?: number,
immediate?: boolean,
) => {
let timeout: NodeJS.Timeout | null = null

return function debounced(this: typeof func, ...args: any[]) {
return function debounced(this: T, ...args: A): void {
const later = () => {
timeout = null
if (!immediate) {
Expand Down

0 comments on commit dc3e8c1

Please sign in to comment.