Closed
Description
Hello!
Thank you for your hard work.
Please, consider this code:
class Foo {
foo: string;
}
class Bar {
bar: string;
}
function foo(value: Foo | Bar) {
const isFoo = value instanceof Foo;
const isBar = !isFoo && value.bar; // <-- causes error
}
The line above throws an error:
Property 'bar' does not exist on type 'Foo | Bar'.
Property 'bar' does not exist on type 'Foo'.
However, if I replace the logical variable with the expression directly, it works:
const isBar = !(value instanceof Foo) && value.bar;
The isFoo
variable in my example is a boolean constant, it's value can't change, so I believe it should be statically analyzable.