[p-waterfall] Add types

This commit is contained in:
Dimitri Benin
2018-12-16 12:19:00 +01:00
parent 39b514a4bb
commit bda645380d
4 changed files with 292 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
// Type definitions for p-waterfall 1.0
// Project: https://github.com/sindresorhus/p-waterfall#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
export = pWaterfall;
type Task<T, R> = (previousValue: T) => R | PromiseLike<R>;
type InitialTask<R> = () => R | PromiseLike<R>;
declare function pWaterfall<R>(tasks: [InitialTask<R>]): Promise<R>;
declare function pWaterfall<T1, R>(tasks: [InitialTask<T1>, Task<T1, R>]): Promise<R>;
declare function pWaterfall<T1, T2, R>(
tasks: [InitialTask<T1>, Task<T1, T2>, Task<T2, R>]
): Promise<R>;
declare function pWaterfall<T1, T2, T3, R>(
tasks: [InitialTask<T1>, Task<T1, T2>, Task<T2, T3>, Task<T3, R>]
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, R>(
tasks: [InitialTask<T1>, Task<T1, T2>, Task<T2, T3>, Task<T3, T4>, Task<T4, R>]
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, R>(
tasks: [InitialTask<T1>, Task<T1, T2>, Task<T2, T3>, Task<T3, T4>, Task<T4, T5>, Task<T5, R>]
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, T6, R>(
tasks: [
InitialTask<T1>,
Task<T1, T2>,
Task<T2, T3>,
Task<T3, T4>,
Task<T4, T5>,
Task<T5, T6>,
Task<T6, R>
]
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, T6, T7, R>(
tasks: [
InitialTask<T1>,
Task<T1, T2>,
Task<T2, T3>,
Task<T3, T4>,
Task<T4, T5>,
Task<T5, T6>,
Task<T6, T7>,
Task<T7, R>
]
): Promise<R>;
declare function pWaterfall<T1, R>(tasks: [Task<T1, R>], initialValue: T1): Promise<R>;
declare function pWaterfall<T1, T2, R>(
tasks: [Task<T1, T2>, Task<T2, R>],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, R>(
tasks: [Task<T1, T2>, Task<T2, T3>, Task<T3, R>],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, R>(
tasks: [Task<T1, T2>, Task<T2, T3>, Task<T3, T4>, Task<T4, R>],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, R>(
tasks: [Task<T1, T2>, Task<T2, T3>, Task<T3, T4>, Task<T4, T5>, Task<T5, R>],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, T6, R>(
tasks: [Task<T1, T2>, Task<T2, T3>, Task<T3, T4>, Task<T4, T5>, Task<T5, T6>, Task<T6, R>],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, T6, T7, R>(
tasks: [
Task<T1, T2>,
Task<T2, T3>,
Task<T3, T4>,
Task<T4, T5>,
Task<T5, T6>,
Task<T6, T7>,
Task<T7, R>
],
initialValue: T1
): Promise<R>;
declare function pWaterfall<T1, T2, T3, T4, T5, T6, T7, T8, R>(
tasks: [
Task<T1, T2>,
Task<T2, T3>,
Task<T3, T4>,
Task<T4, T5>,
Task<T5, T6>,
Task<T6, T7>,
Task<T7, T8>,
Task<T8, R>
],
initialValue: T1
): Promise<R>;
declare function pWaterfall(tasks: Iterable<Task<any, any>>, initialValue?: any): Promise<any>;
+171
View File
@@ -0,0 +1,171 @@
import pWaterfall = require('p-waterfall');
pWaterfall([() => `I ❤️ unicorn`]).then(finalValue => {
// $ExpectType string
finalValue;
});
pWaterfall([() => `I ❤️ unicorn`, (str: string) => true]).then(finalValue => {
// $ExpectType boolean
finalValue;
});
pWaterfall([() => `I ❤️ unicorn`, (str: string) => true, (bool: boolean) => 1]).then(finalValue => {
// $ExpectType number
finalValue;
});
pWaterfall([
() => `I ❤️ unicorn`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
]).then(finalValue => {
// $ExpectType null
finalValue;
});
pWaterfall([
() => `I ❤️ unicorn`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
]).then(finalValue => {
// $ExpectType undefined
finalValue;
});
pWaterfall([
() => `I ❤️ unicorn`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
]).then(finalValue => {
// $ExpectType {}
finalValue;
});
pWaterfall([
() => `I ❤️ unicorn`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
(o: {}) => 'foo',
]).then(finalValue => {
// $ExpectType string
finalValue;
});
pWaterfall([
() => `I ❤️ unicorn`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
(o: {}) => 'foo',
(s: string) => 1,
]).then(finalValue => {
// $ExpectType number
finalValue;
});
pWaterfall([previousValue => `I ❤️ ${previousValue}`], 'unicorn').then(finalValue => {
// $ExpectType string
finalValue;
});
pWaterfall([previousValue => `I ❤️ ${previousValue}`, (str: string) => true], 'unicorn').then(
finalValue => {
// $ExpectType boolean
finalValue;
}
);
pWaterfall(
[previousValue => `I ❤️ ${previousValue}`, (str: string) => true, (bool: boolean) => 1],
'unicorn'
).then(finalValue => {
// $ExpectType number
finalValue;
});
pWaterfall(
[
previousValue => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
],
'unicorn'
).then(finalValue => {
// $ExpectType null
finalValue;
});
pWaterfall(
[
previousValue => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
],
'unicorn'
).then(finalValue => {
// $ExpectType undefined
finalValue;
});
pWaterfall(
[
previousValue => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
],
'unicorn'
).then(finalValue => {
// $ExpectType {}
finalValue;
});
pWaterfall(
[
previousValue => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
(o: {}) => 'foo',
],
'unicorn'
).then(finalValue => {
// $ExpectType string
finalValue;
});
pWaterfall(
[
previousValue => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
(u: undefined) => ({}),
(o: {}) => 'foo',
(s: string) => 1,
],
'unicorn'
).then(finalValue => {
// $ExpectType number
finalValue;
});
pWaterfall(
new Set([
(previousValue: string) => `I ❤️ ${previousValue}`,
(str: string) => true,
(bool: boolean) => 1,
(num: number) => null,
(n: null) => undefined,
]),
'unicorn'
).then(finalValue => {
// $ExpectType any
finalValue;
});
+23
View File
@@ -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-waterfall-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }