Sam Verschueren
6 years ago
committed by
Sindre Sorhus
4 changed files with 32 additions and 3 deletions
@ -0,0 +1,13 @@ |
|||
/** |
|||
* Check if `input` is a ES2015 promise. |
|||
* |
|||
* @param input - Value to be checked. |
|||
* |
|||
* @example |
|||
* |
|||
* import isPromise from 'p-is-promise'; |
|||
* |
|||
* isPromise(Promise.resolve('🦄')); |
|||
* //=> true
|
|||
*/ |
|||
export default function(input: unknown): input is Promise<unknown>; |
@ -0,0 +1,11 @@ |
|||
import {expectType} from 'tsd-check'; |
|||
import isPromise from '.'; |
|||
|
|||
expectType<boolean>(isPromise('🦄')); |
|||
|
|||
const unicorn: unknown = Promise.resolve('🦄'); |
|||
|
|||
if (isPromise(unicorn)) { |
|||
expectType<Promise<unknown>>(unicorn); |
|||
expectType<unknown>(await unicorn); |
|||
} |
Loading…
Reference in new issue