TypeScript Version: 2.2.0
--strictNullChecks must be used.
Code
interface Foo {
name: () => string;
}
let foo: Foo;
setTimeout((() => foo.name()), 0);
Expected behavior:
Error at let foo: Foo line since the compiler is implicitly doing let foo: Foo = undefined;.
If I were to write the = undefined initializer myself, the compiler properly errors with:
Type 'undefined' is not assignable to type 'Foo'.
Actual behavior:
The code compiles and errors at runtime:
TypeError: foo is undefined
TypeScript Version: 2.2.0
--strictNullChecksmust be used.Code
Expected behavior:
Error at
let foo: Fooline since the compiler is implicitly doinglet foo: Foo = undefined;.If I were to write the
= undefinedinitializer myself, the compiler properly errors with:Actual behavior:
The code compiles and errors at runtime: