Great question. The main reason here is that TypeScript does not know that the callback is called immediately and thus makes a conservative assumption that the function can be called later after other assignments could happen.
Consider the following code:
let x: string | number = "hello world";
foo(() => console.log(x.substr(2)));
x = 42;
? . , foo (, foo is window.setTimeout). !
, const let, TypeScript , "":
const arr:(number|string)[] = [1, 2];
if (isNumberArray(arr)) {
let res1: number = arr[1];
let res2: number = [1].map(i => arr[i])[0];
}