main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
775 bytes
|
Line | |
---|
1 | /**
|
---|
2 | Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
---|
3 |
|
---|
4 | Use-cases:
|
---|
5 | - A function accepts a callback that may either return a value synchronously or may return a promised value.
|
---|
6 | - This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
|
---|
7 |
|
---|
8 | Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
|
---|
9 |
|
---|
10 | @example
|
---|
11 | ```
|
---|
12 | import {Promisable} from 'type-fest';
|
---|
13 |
|
---|
14 | async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
|
---|
15 | const entry = await getLogEntry();
|
---|
16 | console.log(entry);
|
---|
17 | }
|
---|
18 |
|
---|
19 | logger(() => 'foo');
|
---|
20 | logger(() => Promise.resolve('bar'));
|
---|
21 | ```
|
---|
22 | */
|
---|
23 | export type Promisable<T> = T | PromiseLike<T>;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.