For some reason type guards to not work if an interface has only optional properties.
interface A {
foo : number;
}
function isA(object: any): object is A {
return true;
}
let a: A | boolean;
if (isA(a)) {
a.foo; // compiles
}
interface B {
foo? : number;
}
function isB(object: any): object is B {
return true;
}
let b: B | boolean;
if (isB(b)) {
b.foo; // does not compile because type inference says its `B | boolean`
}