cf.completefrontend

Write the codeHard

Type debounce(fn, wait) so the returned function takes exactly the same arguments as fn.

Add types to this JavaScript debounce, without any. The debounced function must accept exactly fn's parameters, keep the this it's called with, and return void, since fn runs later. The timer variable must type-check in the browser.

Write this
function debounce(fn, wait) {  let timer;  return function (...args) {    clearTimeout(timer);    timer = setTimeout(() => fn.apply(this, args), wait);  };} // const save = debounce((text: string) => console.log(text), 300);// save("draft"); // logs "draft" 300 ms after the last call// save(42);      // should be a type error

Solve it in the editor

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…