What is the correct fix?
function len(v: any) {
return v.length;
}
len(42);
- Type it as
string | unknown[]instead - Type it as
object | unknown[]instead - Add a
// @ts-ignoreabove the call - Return
v?.lengthto guard the access
any disables checking entirely, so a number slips through; narrow the parameter type.