Throttle a Function, Keeping Its Types

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write throttle(fn, ms): return a function that calls fn straight away and returns its result, then ignores calls (returning undefined, with no call later) until ms milliseconds have passed since fn last ran. Type it so the throttled function takes exactly fn's parameters and returns fn's return type or undefined.

Your code must pass

  • Calls fn straight away with the first arguments
  • Ignores calls within the wait
  • Calls fn again once the wait has passed
  • Has no type errors
  • Takes fn's parameters
  • Returns fn's result or undefined