[p-forever] Add types

This commit is contained in:
Dimitri Benin
2018-12-16 14:54:26 +01:00
parent 39b514a4bb
commit 44ebf6a3d7
4 changed files with 76 additions and 0 deletions

19
types/p-forever/index.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// Type definitions for p-forever 1.0
// Project: https://github.com/sindresorhus/p-forever#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
export = pForever;
declare function pForever<T>(
fn: (previousValue?: T) => T | PromiseLike<T> | typeof pForever.end
): Promise<void>;
declare function pForever<T>(
fn: (previousValue: T) => T | PromiseLike<T> | typeof pForever.end,
initialValue: T
): Promise<void>;
declare namespace pForever {
const end: unique symbol;
}

View File

@@ -0,0 +1,33 @@
import pForever = require('p-forever');
// $ExpectType Promise<void>
pForever(i => {
// $ExpectType number
i;
i++;
return i <= 100 ? i : pForever.end;
}, 0);
// $ExpectType Promise<void>
pForever(i => {
// $ExpectType number
i;
i++;
return i <= 100 ? Promise.resolve(i) : pForever.end;
}, 0);
let i = 0;
// $ExpectType Promise<void>
pForever<number>(prevI => {
// $ExpectType number | undefined
prevI;
i++;
return i <= 100 ? i : pForever.end;
});
// $ExpectType Promise<void>
pForever<number>(prevI => {
// $ExpectType number | undefined
prevI;
i++;
return i <= 100 ? Promise.resolve(i) : pForever.end;
});

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-forever-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }