[p-tap] introduce typings (#18711)

This commit is contained in:
Dimitri Benin
2017-08-08 22:57:54 +02:00
committed by Mohamed Hegazy
parent 48e27a5c81
commit 3c43f5038a
4 changed files with 62 additions and 0 deletions

13
types/p-tap/index.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
// Type definitions for p-tap 1.0
// Project: https://github.com/sindresorhus/p-tap#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = pTap;
declare const pTap: pTap;
interface pTap {
<T>(fn: (value: T) => any): (value: T) => Promise<T>;
catch(fn: (value: any) => any): (value: any) => Promise<never>;
}

View File

@@ -0,0 +1,26 @@
import pTap = require('p-tap');
Promise.resolve('unicorn')
.then(pTap<string>(val => {
let str: string = val;
return 1;
}))
.then(val => {
let str: string = val;
});
Promise.resolve('unicorn')
.then(pTap<string>(val => {
let str: string = val;
return Promise.resolve(1);
}))
.then(val => {
let str: string = val;
});
Promise.reject(new Error())
.catch(pTap.catch(val => {
const num: number = val;
}))
.then(() => 1)
.catch(() => {});

22
types/p-tap/tsconfig.json Normal file
View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"p-tap-tests.ts"
]
}

1
types/p-tap/tslint.json Normal file
View File

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