Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
beaucollins committed Jan 3, 2019
2 parents 2142d4c + 0c27d3b commit 7148f54
Show file tree
Hide file tree
Showing 15 changed files with 1,693 additions and 70 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 @@ -1394,13 +1393,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 @@ -1609,7 +1608,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 @@ -2352,14 +2351,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 @@ -2380,9 +2379,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 @@ -2483,8 +2482,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 @@ -3155,18 +3153,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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
declare module "nanoevents" {
declare export default class NanoEvents {
constructor(): NanoEvents,
declare export default class NanoEvents<T> {
constructor(): NanoEvents<T>,

on(event: string, cb: (any) => void): void,
on<K: $Keys<T>>(event: K, cb: ($ElementType<T, K>) => void): void,

emit(event: string, data?: any): void
emit<K: $Keys<T>>(event: K, data?: $ElementType<T, K>): void
}
}
77 changes: 57 additions & 20 deletions definitions/npm/nanoevents_v1.0.x/test_nanoevents_v1.0.x.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
import { describe, it } from "flow-typed-test";
import NanoEvents from "nanoevents";

// $ExpectError: call a constructor
NanoEvents();
describe("default", () => {
it("should create instance", () => {
// $ExpectError: call a constructor
NanoEvents();

// $ExpectError: not accept arguments
new NanoEvents(1);
// $ExpectError: not accept arguments
new NanoEvents(1);

const emitter = new NanoEvents();
const emitter = new NanoEvents();

emitter.emit("event");
emitter.emit("message");

// $ExpectError: allow only string as event name
emitter.emit(1);
// $ExpectError: allow only string as event name
emitter.emit(1);

emitter.emit("event", {});
emitter.emit("event", 1);
emitter.emit("event", "");
emitter.emit("event", true);
emitter.emit("event", {});
emitter.emit("event", 1);
emitter.emit("event", "");
emitter.emit("event", true);

emitter.on("event", () => {});
emitter.on("event", () => {});

emitter.on("event", arg => {
console.log(arg);
});
emitter.on("event", arg => {
console.log(arg);
});

// $ExpectError: allow only string as even name
emitter.on(1, () => {});

// $ExpectError: allow only functions as callback
emitter.on("event", 1);
});

it('should throw error on emit wrong type', () => {
const emitter = new NanoEvents<{ message: 'message-1' | 'message-2', error: Error }>();

// $ExpectError: allow only message-1 or message-2 strings
emitter.emit('message', 1);
emitter.emit('message', 'message-1');
emitter.emit('message', 'message-2');

// $ExpectError: allow only string as even name
emitter.on(1, () => {});
// $ExpectError: allow only Error
emitter.emit('error', 'error message');
emitter.emit('error', new Error('error message'));

// $ExpectError: allow only functions as callback
emitter.on("event", 1);
// $ExpectError: allow only message or string events
emitter.emit('wrong event');
});

it('should throw error on handle wrong event type or wrong handler type', () => {
const emitter = new NanoEvents<{ message: 'message-1' | 'message-2', error: Error }>();

emitter.on('message', message => {
// $ExpectError: allow only message-1 or message-2 strings
(message: 'wrong message');
(message: 'message-1' | 'message-2');
});

emitter.on('error', error => {
// $ExpectError: allow only Error instance
(error: string);
(error: Error);
})
});
});

0 comments on commit 7148f54

Please sign in to comment.