While working with TypeScript, I encountered a scenario similar to the code snippet below:
const getString = (string: string) => string
// No errors
getString("foo");
// Argument of type 'boolean' is not assignable to parameter of type 'string'.ts(2345)
getString(false && "foo");
// No errors
getString(1 > 2 && "foo");
I found it interesting that no error was thrown for
getString(1 > 2 && "foo")
. Despite the fact that 1 > 2
evaluates to false, a boolean value, which getString()
cannot accept. Why did TypeScript not evaluate 1 > 2
and raise an error in this case?