Back to questions
JuniorTheoryCommon
What does tsc report for this program?
function area(w: number, h: number) {
return w * h;
}
console.log(area(3));An error: 2 arguments are expected, but 1 is passed
- Expecting
NaN, as in JavaScript:tscchecks the number of arguments against the signature and reports errorTS2554before the program runs. - Expecting a missing argument to become
0: TypeScript fills in nothing, and only?or a default value such ash = 1lets a caller leave it out.
- How would you change
areaso thatarea(3)compiles and the missing side counts as1? - What does tsc report for the call
area(3, 4, 5)?