Can someone explain why the following typescript can't catch the typing problem?
function z(a: number) {
console.log(a*a);
}
z(1); // works
z("xyz"); // fails type checking
function y(a: any){
z(a); // I expect this statement to be erroneous
}
y(1); // works
y("xyz"); // does not fail type checking; feels like duck-typing?
In the example above, the compiler knows that y is being passed a string
and therefore z
is being passed a string. This should be sufficient for a transpiler error. Could someone explain the decisions that went into the transpiler design?
Thank you! :)