Reputation: 11
I'm new to Flow and am wondering why a couple 'basic' issues don't raise any warnings in Flow:
let foo: Array<{| id: string, occursOn: string |}>;
foo = [{ id: "5", occursOn: "2017-01-01" }];
// Not a flow error!
console.log(foo[0][0].bar);
const grouped = groupBy(foo, "occursOn");
// Not a flow error!
console.log(grouped["2017-01-01"].bar);
Why is accessing foo[0][0].bar
ok in Flow, when I have been explicit about the type of foo
?
Similarly, I have lodash
installed via flow-typed
, yet grouped["2017-01-01"].bar
seems to be totally fine in Flow?
Upvotes: 1
Views: 41
Reputation: 161467
Your first example with the array index seems like this bug: https://github.com/facebook/flow/issues/4257
For the groupBy
, most likely you just haven't told Flow what groupBy
does. I'd assume you're doing
import { groupBy } from 'lodash';
and by default Flowtype doesn't have any way to know what the lodash
module is or what its functions do, so you need to install type definitions for Lodash, and hope that you're not using too much runtime magic so it'll give you a reasonable type signature.
For your case, you do get the error when Flow knows what type it is, which you can see here.
Upvotes: 1