Skip to content

Commit

Permalink
Fixing lodash defs for flow 0.88.0+ (#3020)
Browse files Browse the repository at this point in the history
* Fixing lodash defs for flow 0.88.0+

* Folders are correctly named now

* Return value is a boolean

* comment was used to trigger tests

* More correct partial definitions

* More generic function types

* Better generics for functions

* Using any as mixed fails type captures
  • Loading branch information
beaucollins authored and villesau committed Jan 3, 2019
1 parent f8afc4c commit 0c27d3b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
72 changes: 35 additions & 37 deletions definitions/npm/lodash_v4.x.x/flow_v0.63.x-/lodash_v4.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ declare module "lodash" {

declare type NestedArray<T> = Array<Array<T>>;

declare type matchesIterateeShorthand = Object;
declare type matchesIterateeShorthand = {[key: any]: any};
declare type matchesPropertyIterateeShorthand = [string, any];
declare type propertyIterateeShorthand = string;

Expand Down Expand Up @@ -746,8 +746,8 @@ declare module "lodash" {
shuffle<T>(array: ?Array<T>): Array<T>;
shuffle<V, T: Object>(object: T): Array<V>;
size(collection: $ReadOnlyArray<any> | Object | string): number;
some<T>(array: ?$ReadOnlyArray<T>, predicate?: Predicate<T>): boolean;
some<T>(array: void | null, predicate?: ?Predicate<T>): false;
some<T>(array: ?$ReadOnlyArray<T>, predicate?: Predicate<T>): boolean;
some<A, T: { [id: any]: A }>(
object?: ?T,
predicate?: OPredicate<A, T>
Expand Down Expand Up @@ -776,33 +776,33 @@ declare module "lodash" {
after(n: number, fn: Function): Function;
ary(func: Function, n?: number): Function;
before(n: number, fn: Function): Function;
bind(func: Function, thisArg: any, ...partials: Array<any>): Function;
bind<F:(...any[]) => any>(func: F, thisArg: any, ...partials: Array<any>): F;
bindKey(obj?: ?Object, key?: ?string, ...partials?: Array<?any>): Function;
curry: Curry;
curry(func: Function, arity?: number): Function;
curryRight(func: Function, arity?: number): Function;
debounce<F: Function>(func: F, wait?: number, options?: DebounceOptions): F;
defer(func: Function, ...args?: Array<any>): TimeoutID;
debounce<F: (...any[]) => any>(func: F, wait?: number, options?: DebounceOptions): F;
defer(func: (...any[]) => any, ...args?: Array<any>): TimeoutID;
delay(func: Function, wait: number, ...args?: Array<any>): TimeoutID;
flip(func: Function): Function;
memoize<F: Function>(func: F, resolver?: Function): F;
negate(predicate: Function): Function;
once(func: Function): Function;
flip<R>(func: (...any[]) => R): (...any[]) => R;
memoize<A, R>(func: (...A) => R, resolver?: (...A) => any): (...A) => R;
negate<A, R>(predicate: (...A) => R): (...A) => boolean;
once<F: (...any[]) => any>(func: F): F;
overArgs(func?: ?Function, ...transforms?: Array<Function>): Function;
overArgs(func?: ?Function, transforms?: ?Array<Function>): Function;
partial(func: Function, ...partials: any[]): Function;
partialRight(func: Function, ...partials: Array<any>): Function;
partialRight(func: Function, partials: Array<any>): Function;
partial<R>(func: (...any[]) => R, ...partials: any[]): (...any[]) => R;
partialRight<R>(func: (...any[]) => R, ...partials: Array<any>): (...any[]) => R;
partialRight<R>(func: (...any[]) => R, partials: Array<any>): (...any[]) => R;
rearg(func: Function, ...indexes: Array<number>): Function;
rearg(func: Function, indexes: Array<number>): Function;
rest(func: Function, start?: number): Function;
spread(func: Function): Function;
throttle(
func: Function,
throttle<F: (...any[]) => any>(
func: F,
wait?: number,
options?: ThrottleOptions
): Function;
unary(func: Function): Function;
): F;
unary<F: (...any[]) => any>(func: F): F;
wrap(value?: any, wrapper?: ?Function): Function;

// Lang
Expand Down Expand Up @@ -891,12 +891,10 @@ declare module "lodash" {
isNull(value: any): false;
isNumber(value: number): true;
isNumber(value: any): false;
isObject(value: Object): true;
isObject(value: any): false;
isObject(value: any): boolean;
isObjectLike(value: void | null): false;
isObjectLike(value: any): boolean;
isPlainObject(value: Object): true;
isPlainObject(value: any): false;
isPlainObject(value: any): boolean;
isRegExp(value: RegExp): true;
isRegExp(value: any): false;
isSafeInteger(value: number): boolean;
Expand Down Expand Up @@ -1066,6 +1064,7 @@ declare module "lodash" {
): Object;
at(object?: ?Object, ...paths: Array<string>): Array<any>;
at(object?: ?Object, paths: Array<string>): Array<any>;
create(prototype: void | null, properties: void | null): {};
create<T>(prototype: T, properties: Object): $Supertype<T>;
create(prototype: any, properties: void | null): {};
defaults(object?: ?Object, ...sources?: Array<?Object>): Object;
Expand Down Expand Up @@ -1283,8 +1282,8 @@ declare module "lodash" {
iteratee?: ?OIteratee<*>,
accumulator?: ?any
): {};
unset(object: Object, path?: ?Array<string> | ?string): boolean;
unset(object: void | null, path?: ?Array<string> | ?string): true;
unset(object: Object, path?: ?Array<string> | ?string): boolean;
update(object: Object, path: string[] | string, updater: Function): Object;
update<T: void | null>(
object: T,
Expand Down Expand Up @@ -1393,13 +1392,13 @@ declare module "lodash" {
cond(pairs?: ?NestedArray<Function>): Function;
conforms(source?: ?Object): Function;
constant<T>(value: T): () => T;
defaultTo<T1: string | boolean | Object, T2>(
defaultTo<T1: void | null, T2>(value: T1, defaultValue: T2): T2;
defaultTo<T1: string | boolean, T2>(
value: T1,
defaultValue: T2
): T1;
// NaN is a number instead of its own type, otherwise it would behave like null/void
defaultTo<T1: number, T2>(value: T1, defaultValue: T2): T1 | T2;
defaultTo<T1: void | null, T2>(value: T1, defaultValue: T2): T2;
flow: $ComposeReverse & ((funcs: Array<Function>) => Function);
flowRight: $Compose & ((funcs: Array<Function>) => Function);
identity<T>(value: T): T;
Expand Down Expand Up @@ -1608,7 +1607,7 @@ declare module "lodash/fp" {

declare type NestedArray<T> = Array<Array<T>>;

declare type matchesIterateeShorthand = Object;
declare type matchesIterateeShorthand = {[string | number]: any};
declare type matchesPropertyIterateeShorthand = [string, any];
declare type propertyIterateeShorthand = string;

Expand Down Expand Up @@ -2351,14 +2350,14 @@ declare module "lodash/fp" {
curryRight(func: Function): Function;
curryRightN(arity: number): (func: Function) => Function;
curryRightN(arity: number, func: Function): Function;
debounce(wait: number): <F: Function>(func: F) => F;
debounce<F: Function>(wait: number, func: F): F;
defer(func: Function): TimeoutID;
debounce(wait: number): <A, R>(func: (...A) => R) => (...A) => R;
debounce<A, R>(wait: number, func: (...A) => R): (...A) => R;
defer(func: (...any[]) => any): TimeoutID;
delay(wait: number): (func: Function) => TimeoutID;
delay(wait: number, func: Function): TimeoutID;
flip(func: Function): Function;
memoize<F: Function>(func: F): F;
negate(predicate: Function): Function;
negate<A, R>(predicate: (...A) => R): (...A) => boolean;
complement(predicate: Function): Function;
once(func: Function): Function;
overArgs(func: Function): (transforms: Array<Function>) => Function;
Expand All @@ -2379,9 +2378,9 @@ declare module "lodash/fp" {
apply(func: Function): Function;
spreadFrom(start: number): (func: Function) => Function;
spreadFrom(start: number, func: Function): Function;
throttle(wait: number): (func: Function) => Function;
throttle(wait: number, func: Function): Function;
unary(func: Function): Function;
throttle<A, R>(wait: number): (func: (...A) => R) => (...A) => R;
throttle<A, R>(wait: number, func: (...A) => R): (...A) => R;
unary<T, R>(func: (T, ...any[]) => R): (T) => R;
wrap(wrapper: Function): (value: any) => Function;
wrap(wrapper: Function, value: any): Function;

Expand Down Expand Up @@ -2482,8 +2481,7 @@ declare module "lodash/fp" {
): boolean;
isError(value: any): boolean;
isFinite(value: any): boolean;
isFunction(value: Function): true;
isFunction(value: number | string | void | null | Object): false;
isFunction(value: any): boolean;
isInteger(value: any): boolean;
isLength(value: any): boolean;
isMap(value: any): boolean;
Expand Down Expand Up @@ -3154,18 +3152,18 @@ declare module "lodash/fp" {
cond(pairs: NestedArray<Function>): Function;
constant<T>(value: T): () => T;
always<T>(value: T): () => T;
defaultTo<T1: string | boolean | Object, T2>(
defaultTo<T1: void | null, T2>(defaultValue: T2): (value: T1) => T2;
defaultTo<T1: void | null, T2>(defaultValue: T2, value: T1): T2;
defaultTo<T1: string | boolean, T2>(
defaultValue: T2
): (value: T1) => T1;
defaultTo<T1: string | boolean | Object, T2>(
defaultTo<T1: string | boolean, T2>(
defaultValue: T2,
value: T1
): T1;
// NaN is a number instead of its own type, otherwise it would behave like null/void
defaultTo<T1: number, T2>(defaultValue: T2): (value: T1) => T1 | T2;
defaultTo<T1: number, T2>(defaultValue: T2, value: T1): T1 | T2;
defaultTo<T1: void | null, T2>(defaultValue: T2): (value: T1) => T2;
defaultTo<T1: void | null, T2>(defaultValue: T2, value: T1): T2;
flow: $ComposeReverse & ((funcs: Array<Function>) => Function);
pipe: $ComposeReverse & ((funcs: Array<Function>) => Function);
flowRight: $Compose & ((funcs: Array<Function>) => Function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ import first from "lodash/first";
(isEqualWith(null, null, null): boolean);
(isError(null): false);
(isFinite(null): false);
(isFunction(null): false);
(isFunction(null): boolean);
(isInteger(null): false);
(isLength(null): false);
(isMap(null): false);
Expand All @@ -445,9 +445,9 @@ import first from "lodash/first";
(isNil(null): true);
(isNull(null): true);
(isNumber(null): false);
(isObject(null): false);
(isObject(null): boolean);
(isObjectLike(null): false);
(isPlainObject(null): false);
(isPlainObject(null): boolean);
(isRegExp(null): false);
(isSafeInteger(null): false);
(isSet(null): false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ opaque type O = string;
const v: { [O]: number } = { x: 1, y: 2 };
find(v, { x: 3 });

// $ExpectError undefined. This type is incompatible with object type.
var result: Object = find(users, "active");

/**
* _.find examples from the official doc
*/
Expand Down Expand Up @@ -377,9 +374,9 @@ boolTrue = isString(undefined);
/**
* _.find
*/
find([1, 2, 3], x => x == 1);
(find([1, 2, 3], x => x == 1): void | number);
// $ExpectError number. This type is incompatible with function type.
find([1, 2, 3], 1);
(find([1, 2, 3], 1): void | number);

// Copy pasted tests from iflow-lodash
var nums: number[] = [1, 2, 3, 4, 5, 6];
Expand Down

0 comments on commit 0c27d3b

Please sign in to comment.