flow
flow copied to clipboard
Sealed object properties not checked in conditionals
Is it correct that sealed object properties are not checked in conditional statements?
For example:
// Create a sealed object
const o = {
Foo: 'Foo',
};
// Reports an Error
const fooz = o.Fooz;
// Reports an Error
const x = o.Fooz === 'Bar';
// Does not report an error
if (o.Fooz === 'Bar') {}
// Does not report an error
const y = (o.Fooz === 'Bar') ? true : false;
Edit: Added some more examples. It looks like intermediate expressions (the if statement and the ternary) do not have the type check applied.
Non-existence is not an error within a conditional expression. See the comment from https://github.com/facebook/flow/blob/c9131da361ab03e64227d870ec113bd030993a3e/src/typing/statement.ml#L4453-L4456
@popham many thanks for clarifying.