mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
[p-reflect] add typings (#18863)
This commit is contained in:
committed by
Mohamed Hegazy
parent
e09f8c00cd
commit
3a5ef9918f
24
types/p-reflect/index.d.ts
vendored
Normal file
24
types/p-reflect/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
15
types/p-reflect/p-reflect-tests.ts
Normal file
15
types/p-reflect/p-reflect-tests.ts
Normal 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
|
||||
}
|
||||
});
|
||||
22
types/p-reflect/tsconfig.json
Normal file
22
types/p-reflect/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/p-reflect/tslint.json
Normal file
1
types/p-reflect/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user