13.
Will TypeScript detect a problem with the following code? If so, what's the problem?
function multiply(a: number, b: string): number {
return a * b;
}
The code has a syntax error.
TypeScript will not detect a problem with this code.
No, there is no problem.
Yes: Type 'string' is not assignable to type 'number'
Correct: D
Yes, TypeScript will detect a problem with this code. The problem is that the function multiply is declared to accept two parameters, a and b, with specific types: number and string, respectively and returns a number. However, in the return statement return a * b;, the operation a * b is trying to multiply a number with a string, which is not valid. TypeScript's static type checking will flag this as an error: Type 'string' is not assignable to type 'number'.