Merge pull request #31449 from BendingBender/p-time

[p-time] Add types
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 09:11:06 -08:00
committed by GitHub
4 changed files with 67 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// Type definitions for p-time 1.0
// Project: https://github.com/sindresorhus/p-time#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
export = pTime;
declare function pTime<TArgs extends any[], TRes>(
fn: (...args: TArgs) => PromiseLike<TRes>
): (...args: TArgs) => pTime.PromiseWithTime<TRes>;
declare namespace pTime {
const log: typeof pTime;
interface PromiseWithTime<T> extends Promise<T> {
time?: number;
}
}
+24
View File
@@ -0,0 +1,24 @@
import pTime = require('p-time');
const wrappedFn = pTime(async (input: number) => {
return input;
});
// $ExpectType (input: number) => PromiseWithTime<number>
wrappedFn;
// $ExpectType number | undefined
wrappedFn(1).time;
// $ExpectError
pTime((input: number) => {
return input;
});
// $ExpectError
wrappedFn('foo');
// $ExpectType (input: number) => PromiseWithTime<number>
pTime.log(async (input: number) => {
return input;
});
+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-time-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }