Use Typescript generics for a type safe `setTimeout` and `setInterval`TLDR; Here's the code: type Handler = ((...args: any[]) => any) | string; function safeSetTimeout<F extends Handler>( handler: F, timeout?: number, ...args: F extends string ? any[] : Parameters<F extends string ? never : F> ) { retu...5 min read·abdellahcodes.comMar 23, 2022
Use Typescript generics for a type safe `setTimeout` and `setInterval`TLDR; Here's the code: type Handler = ((...args: any[]) => any) | string; function safeSetTimeout<F extends Handler>( handler: F, timeout?: number, ...args: F extends string ? any[] : Parameters<F extends string ? never : F> ) { retu...5 min read·abdellahcodes.comMar 20, 2022
Promises: run any promise with a timeoutPromise.race() provides a nice primitive to implement custom timeout logic for promises.3 min read·abdellahcodes.comMar 18, 2022
Promises: async/await vs .then(), how we got here and why I use bothHow we got here Promises marked a huge turning point in async js, they enabled a new type of control flow that saved us from callback hell. But some people found that calling .then() multiple times was too much, too callbacky. Then after a while, we ...3 min read·abdellahcodes.com1MMar 16, 2022