As we know, the any data type is the super type of all other data types in TypeScript. I am curious why I can pass a variable of any to a function which requires a parameter of number | undefined type?
let v1: any = 'abc';
let v2: number | undefined = 5;
function foo(p: number | undefined): void {
if (typeof p === "number") {
console.log(Math.pow(p, 2));
} else {
p;
console.log("p is undefined");
}
}
foo(v1); // output: p is undefined. (1)
There is no error in the above code. But I think that v1 shouldn't be a legal argument to the foo function.