Skip to content

Commit

Permalink
[p-filter] Add definitions (#2898)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehollaar authored and villesau committed Oct 26, 2018
1 parent 6c23071 commit 9dfc688
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
@@ -0,0 +1,7 @@
declare module 'p-filter' {
declare export default function PFilter<T>(
input: Iterable<Promise<T> | T>,
filterer: (element: T, index: number) => boolean | Promise<boolean>,
options?: { concurrency?: number },
): Promise<Array<T>>;
}
35 changes: 35 additions & 0 deletions definitions/npm/p-filter_v1.x.x/test_p-filter_v1.x.x.js
@@ -0,0 +1,35 @@
import pFilter from 'p-filter';
import { it } from 'flow-typed-test';

it('handles correct inputs and return type', () => {
(pFilter([1, 2, 3], (el: number, index: number) => true): Promise<
Array<number>,
>);
(pFilter(
['a', 'b', Promise.resolve('c')],
(el: string, index: number) => false,
{ concurrency: 2 },
): Promise<Array<string>>);
});

it('errors on invalid filterer element type', () => {
// $ExpectError
pFilter(['a', 'b', Promise.resolve(3)], (el: string, index: number) => true);
});

it('errors on invalid filterer return type', () => {
// $ExpectError
pFilter([1, 2, Promise.resolve(3)], (el: number, index: number) => null);
});

it('errors on invalid return type', () => {
// $ExpectError
(pFilter([1, 2, 3], (el: number, index: number) => true): Promise<
Array<string>,
>);
});

it('errors on invalid options', () => {
// $ExpectError
pFilter([1, 2, 3], (el: number, index: number) => true, { concurrency: '1' });
});

0 comments on commit 9dfc688

Please sign in to comment.