Reputation: 9663
Here's my code:
// @flow
var x = {a: 'foo'};
var key = Math.random() > 0.5 ? 'b' : 'a';
var value = x.hasOwnProperty(key) ? x[key] : 'default';
console.log(value);
So x[key]
is only accessed if key
really is a property of x
, otherwise a default value is used. But Flow does not like this, it says:
test-flow.js:5
5: var value = x.hasOwnProperty(key) ? x[key] : 'default';
^^^ property `b`. Property not found in
5: var value = x.hasOwnProperty(key) ? x[key] : 'default';
^ object literal
Any idea what I'm doing wrong?
Upvotes: 3
Views: 562