From 305c9cd6dc1b36566d7cd4d44a45c14c56c5b993 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 13 Jan 2019 01:13:32 +0100 Subject: [PATCH] [p-pipe] Add types --- types/p-pipe/index.d.ts | 86 ++++++++++++++++++++++++++++++++++++ types/p-pipe/p-pipe-tests.ts | 57 ++++++++++++++++++++++++ types/p-pipe/tsconfig.json | 23 ++++++++++ types/p-pipe/tslint.json | 1 + 4 files changed, 167 insertions(+) create mode 100644 types/p-pipe/index.d.ts create mode 100644 types/p-pipe/p-pipe-tests.ts create mode 100644 types/p-pipe/tsconfig.json create mode 100644 types/p-pipe/tslint.json diff --git a/types/p-pipe/index.d.ts b/types/p-pipe/index.d.ts new file mode 100644 index 0000000000..2c58bd8f01 --- /dev/null +++ b/types/p-pipe/index.d.ts @@ -0,0 +1,86 @@ +// Type definitions for p-pipe 1.2 +// Project: https://github.com/sindresorhus/p-pipe#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +export = pPipe; + +// tslint:disable:no-unnecessary-generics +declare function pPipe(...args: Tasks1): PromiseTask; +declare function pPipe(...args: Tasks2): PromiseTask; +declare function pPipe(...args: Tasks3): PromiseTask; +declare function pPipe(...args: Tasks4): PromiseTask; +declare function pPipe( + ...args: Tasks5 +): PromiseTask; +declare function pPipe( + ...args: Tasks6 +): PromiseTask; +declare function pPipe( + ...args: Tasks7 +): PromiseTask; +declare function pPipe( + ...args: Tasks8 +): PromiseTask; +declare function pPipe(...args: Array>): PromiseTask; + +declare function pPipe(tasks: Tasks1): PromiseTask; +declare function pPipe(tasks: Tasks2): PromiseTask; +declare function pPipe(tasks: Tasks3): PromiseTask; +declare function pPipe(tasks: Tasks4): PromiseTask; +declare function pPipe( + tasks: Tasks5 +): PromiseTask; +declare function pPipe( + tasks: Tasks6 +): PromiseTask; +declare function pPipe( + tasks: Tasks7 +): PromiseTask; +declare function pPipe( + tasks: Tasks8 +): PromiseTask; +declare function pPipe(tasks: Array>): PromiseTask; + +type Tasks1 = [PromiseTask]; +type Tasks2 = [Task, Task]; +type Tasks3 = [Task, Task, Task]; +type Tasks4 = [Task, Task, Task, Task]; +type Tasks5 = [ + Task, + Task, + Task, + Task, + Task +]; +type Tasks6 = [ + Task, + Task, + Task, + Task, + Task, + Task +]; +type Tasks7 = [ + Task, + Task, + Task, + Task, + Task, + Task, + Task +]; +type Tasks8 = [ + Task, + Task, + Task, + Task, + Task, + Task, + Task, + Task +]; + +type Task = (input: T) => PromiseLike | R; +type PromiseTask = (input: T) => Promise; diff --git a/types/p-pipe/p-pipe-tests.ts b/types/p-pipe/p-pipe-tests.ts new file mode 100644 index 0000000000..8901637430 --- /dev/null +++ b/types/p-pipe/p-pipe-tests.ts @@ -0,0 +1,57 @@ +import pPipe = require('p-pipe'); + +const addUnicorn = (str: string) => Promise.resolve(`${str} Unicorn`); +const addRainbow = (str: string) => Promise.resolve(`${str} Rainbow`); + +const pipeline = pPipe(addUnicorn, addRainbow); + +pipeline('❤️'); // $ExpectType Promise + +const strToInt = (s: string) => Promise.resolve(1); +const intToBool = (i: number) => Promise.resolve(true); +const boolToObj = (b: boolean) => Promise.resolve({}); +const objToNull = (o: object) => Promise.resolve(null); +const nullToVoid = (n: null) => Promise.resolve(undefined); +const voidToStr = (u: undefined) => Promise.resolve(''); + +pPipe(strToInt); // $ExpectType PromiseTask +pPipe(strToInt, intToBool); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj, objToNull); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj, objToNull, nullToVoid); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr, strToInt); // $ExpectType PromiseTask +pPipe(strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr, strToInt, intToBool); // $ExpectType PromiseTask +// $ExpectType PromiseTask +pPipe( + strToInt, + intToBool, + boolToObj, + objToNull, + nullToVoid, + voidToStr, + strToInt, + intToBool, + boolToObj +); + +pPipe([strToInt]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj, objToNull]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj, objToNull, nullToVoid]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr, strToInt]); // $ExpectType PromiseTask +pPipe([strToInt, intToBool, boolToObj, objToNull, nullToVoid, voidToStr, strToInt, intToBool]); // $ExpectType PromiseTask +// $ExpectType PromiseTask +pPipe([ + strToInt, + intToBool, + boolToObj, + objToNull, + nullToVoid, + voidToStr, + strToInt, + intToBool, + boolToObj, +]); diff --git a/types/p-pipe/tsconfig.json b/types/p-pipe/tsconfig.json new file mode 100644 index 0000000000..46cabfcfeb --- /dev/null +++ b/types/p-pipe/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "p-pipe-tests.ts" + ] +} diff --git a/types/p-pipe/tslint.json b/types/p-pipe/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/p-pipe/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }