$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #101

What is the correct fix?

function len(v: any) {
  return v.length;
}
len(42);
  1. Type it as string | unknown[] instead
  2. Type it as object | unknown[] instead
  3. Add a // @ts-ignore above the call
  4. Return v?.length to guard the access
any disables checking entirely, so a number slips through; narrow the parameter type.
Play Problem Solving ▸