Skip to main content
Module

x/scaffold/src/deps/types.ts>Promisable

scaffold your next project with style and 💗
Latest
type alias Promisable
import { type Promisable } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

Create a type that represents either the value or the value wrapped in PromiseLike.

Use-cases:

  • A function accepts a callback that may either return a value synchronously or may return a promised value.
  • This type could be the return type of Promise#then(), Promise#catch(), and Promise#finally() callbacks.

Please upvote this issue if you want to have this type as a built-in in TypeScript.

Examples

Example 1

import type {Promisable} from 'type-fest';

async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
	const entry = await getLogEntry();
	console.log(entry);
}

logger(() => 'foo');
logger(() => Promise.resolve('bar'));
definition: T | PromiseLike<T>