What is the problem with the second situation?
function f(x) {
return (x as string).toLocaleUpperCase();
}
console.log("hello: "+ f("mr.")); // hello: MR.
console.log("hello: "+ f(0));
Uncaught TypeError: x.toLocaleUpperCase is not a function
at f (:2:14)
at :5:25
at HTMLButtonElement.excuteButton.onclick >(https://www.typescriptlang.org/play/playground.js:247)