Это фича?
let x: string;
/*
{
// Variable 'x' is used before being assigned.
x = x;
}
{
// Type 'undefined' is not assignable to type 'string'.
x = undefined;
}
{
// Type 'string | undefined' is not assignable to type 'string'.
// Type 'undefined' is not assignable to type 'string'.
let a: (string|undefined)[] = ["a", "b", "c"];
x = a[0];
}
*/
{
// Успех
let a: string[] = ["a", "b", "c"];
x = a[100];
}
if (x === undefined) {
console.log("WTF?");
}