Which fix removes the bug?
function getLen(s: string): number {
return s.length;
}
const n: number = getLen(42);
- Change return type to
string - Pass a string, e.g.
getLen("42") - Change
s: stringtos: any - Remove the type annotation on n
The argument must be a string to match the parameter type.
Play Problem Solving ▸