flow icon indicating copy to clipboard operation
flow copied to clipboard

Sealed object properties not checked in conditionals

Open kevanstannard opened this issue 8 years ago • 2 comments

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.

kevanstannard avatar Dec 06 '17 02:12 kevanstannard

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 avatar Dec 10 '17 22:12 popham

@popham many thanks for clarifying.

kevanstannard avatar Dec 10 '17 23:12 kevanstannard