"TS2322" Error : Type 'number' is not assignable to type 'Timeout'. (React Native)

2 weeks ago 14
ARTICLE AD BOX

When creating debouncing function using setTimeout , this error with squiggle line saying that number is assignable to type Timeout.

Function Code Snippet :

export const debounce = <T extends (...args : any[]) => any> ( func : T , wait : number ) : ((...args : Parameters<T>) => void) => { let timeout : NodeJS.Timeout; return (...args : Parameters<T>) => { // casting the variable to number clearTimeout(Number(timeout)); timeout = setTimeout(() => func(...args) , wait); }; };
Read Entire Article