flow
flow copied to clipboard
Optional values reporting error after a continue in a loop
/* @flow */
type OptionalValues = {
optional?: {value: string};
}
declare var someValues: OptionalValues[];
for( const ov of someValues) {
if (!ov.optional){
continue;
}
ov.optional.value = 'test'; // Error: property `value`. Property cannot be assigned on possibly undefined value
}
Seems to be very similar to #1167 and #935
@Xesued thanks for the repro - looks like a bug that's specific to continue and property refinements (the latter is what distinguishes it from #1167).
Until fixed, a workaround is to refactor the control flow as follows (if feasible):
for( const ov of someValues) {
if (ov.optional) {
ov.optional.value = 'test'; // no error
break;
}
}
Adding to this, break also exhibits the same bug inside of for loops -- replacing continue with break in the provided repro shows it.
@bhosmer: Mind if I take a look at this one? I feel like writing some OCaml.
This is now fixed.