The type annotation of Lodash's flatMap is less permissive than its implementation
flatMap itself accepts iteratees that have less than 3 parameters, but if you pass an iteratee that only takes 2 parameters, Flow throws a type error:
_.flatMap([], (e, i) => []);
Cannot call _.flatMap because array literal [1] is incompatible with object type [2] in type argument T.
app/components/AssignWidget.jsx
32│ resetErrorMessages: Function
33│ |}> {
34│ selectedTasks = () => {
[1] 35│ _.flatMap([1], (e, i) => []);
36│ return _.flatMap(
37│ this.props.isTaskAssignedToUserSelected[this.props.previousAssigneeId] || [],
38│ (selected, id) => (selected ? [this.props.tasks[id]] : []));
flow-typed/npm/lodash_v4.x.x.js
[2] 557│ flatMap<T: Object, U>(
I think we could fix this by making the parameters of FlatMapIteratee optional.
Seems reasonable, go for it.
If you look at the error message, I don't think it's the number of arguments; it's the fact that the first argument can be an array or an object.
Do I mind if I take this @evankroske ? This is blocking another project.
@CAYdenberg, go for it! I haven't had a chance to work on this. I think you're right that the number of arguments of the callback isn't the issue.
Any news? 😞 Got this error:
Cannot call
_.flatMapbecause array type [1] is incompatible with object type [2] in type argumentT.
At this code:
const result = _.flatMap(order, id =>
_.get(items, [id, 'otherOrder'], [])
);