[p-reflect] add typings (#18863)

This commit is contained in:
Dimitri Benin
2017-08-11 19:08:37 +02:00
committed by Mohamed Hegazy
parent e09f8c00cd
commit 3a5ef9918f
4 changed files with 62 additions and 0 deletions

24
types/p-reflect/index.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
// Type definitions for p-reflect 1.0
// Project: https://github.com/sindresorhus/p-reflect#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = pReflect;
declare function pReflect<T>(promise: PromiseLike<T>): Promise<pReflect.PromiseResult<T>>;
declare namespace pReflect {
type PromiseResult<T> = PromiseFulfilledResult<T> | PromiseRejectedResult;
interface PromiseFulfilledResult<T> {
isFulfilled: true;
isRejected: false;
value: T;
}
interface PromiseRejectedResult {
isFulfilled: false;
isRejected: true;
reason: any;
}
}

View File

@@ -0,0 +1,15 @@
import pReflect = require('p-reflect');
pReflect(Promise.resolve('foo')).then(result => {
if (result.isFulfilled) {
const fulfilled: true = result.isFulfilled;
const rejected: false = result.isRejected;
const str: string = result.value;
result.reason; // $ExpectError
} else {
const fulfilled: false = result.isFulfilled;
const rejected: true = result.isRejected;
const err: any = result.reason;
result.value; // $ExpectError
}
});

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

View File

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