IsPromise
Since 1.3.0
Check if a type is a Promise. Returns true if the type is a Promise, otherwise false.
Signature
typescript
type IsPromise<T> = T extends Promise<any> ? true : falseParameters
| Parameter | Description |
|---|---|
T | The type to check |
Examples
Basic Usage
typescript
import type { IsPromise } from 'uni-types'
type Check1 = IsPromise<Promise<string>> // true
type Check2 = IsPromise<string> // falseWith Generic Types
typescript
import type { IsPromise } from 'uni-types'
type MaybePromise<T> = IsPromise<T> extends true ? T : Promise<T>Conditional Logic
typescript
import type { IsPromise } from 'uni-types'
type UnwrapIfPromise<T> = IsPromise<T> extends true ? PromiseResult<T> : TRelated
PromiseResult- Get resolved value from PromiseWrapPromise- Wrap type in Promise