$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #75

What is the correct fix?

function pick<T>(list: T[], i: number): T {
  return list[i];
}
const v = pick([1, 2], 9);
  1. Return T | undefined and guard the index
  2. Return T | never and guard the index
  3. Change the parameter type to i: T
  4. Mark the whole function as async
An out-of-range index yields undefined, which the declared return type wrongly denies.
Play Problem Solving ▸