Closed
Description
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