Skip to content

Commit

Permalink
lodash: defs for flatmap to work on objects (flow-typed#581)
Browse files Browse the repository at this point in the history
* Add defs for flatmap to work in objects

* Add tests for lodash flatmap

* Make index optional in interatee for flatmap

* Annotate tests to make flow work correctly

* Revert "Make index optional in interatee for flatmap"

This reverts commit aca238d.
  • Loading branch information
ngzhian authored and marudor committed Jan 12, 2017
1 parent f484e50 commit 666888b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions definitions/npm/lodash_v4.x.x/flow_v0.28.x-/lodash_v4.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare module 'lodash' {

declare type OIterateeWithResult<V, O, R> = Object|string|((value: V, key: string, object: O) => R);
declare type OIteratee<O> = OIterateeWithResult<any, O, any>;
declare type OFlatMapIteratee<T, U> = OIterateeWithResult<any, T, Array<U>>;

declare type Predicate<T> =
| ((value: T, index: number, array: Array<T>) => any)
Expand Down Expand Up @@ -179,8 +180,11 @@ declare module 'lodash' {
findLast<T>(array: ?Array<T>, predicate?: Predicate<T>): T;
findLast<V, A, T: {[id: string]: A}>(object: T, predicate?: OPredicate<A, T>): V;
flatMap<T, U>(array: ?Array<T>, iteratee?: FlatMapIteratee<T, U>): Array<U>;
flatMap<T: Object, U>(object: T, iteratee?: OFlatMapIteratee<T, U>): Array<U>;
flatMapDeep<T, U>(array: ?Array<T>, iteratee?: FlatMapIteratee<T, U>): Array<U>;
flatMapDeep<T: Object, U>(object: T, iteratee?: OFlatMapIteratee<T, U>): Array<U>;
flatMapDepth<T, U>(array: ?Array<T>, iteratee?: FlatMapIteratee<T, U>, depth?: number): Array<U>;
flatMapDepth<T: Object, U>(object: T, iteratee?: OFlatMapIteratee<T, U>, depth?: number): Array<U>;
forEach<T>(array: ?Array<T>, iteratee?: Iteratee<T>): Array<T>;
forEach<T: Object>(object: T, iteratee?: OIteratee<T>): T;
forEachRight<T>(array: ?Array<T>, iteratee?: Iteratee<T>): Array<T>;
Expand Down
6 changes: 6 additions & 0 deletions definitions/npm/lodash_v4.x.x/test_lodash-v4.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,9 @@ var strings : string[] = _.times(5);
timesNums = _.times(5, function(i: number) { return i + 1; });
// $ExpectError string. This type is incompatible with number
timesNums = _.times(5, function(i: number) { return JSON.stringify(i); });

// lodash.flatMap for collections and objects
// this arrow function needs a type annotation due to a bug in flow
// https://github.com/facebook/flow/issues/1948
_.flatMap([1, 2, 3], (n): number[] => [n, n]);
_.flatMap({a: 1, b: 2}, n => [n, n]);

0 comments on commit 666888b

Please sign in to comment.