UNPKG

660 BTypeScriptView Raw
1/**
2 * A utility type for choosing between synchronous and asynchronous return
3 * values.
4 *
5 * This is used as the return value for plugins like {@link CustomFunction},
6 * {@link Importer}, and {@link FileImporter} so that TypeScript enforces that
7 * asynchronous plugins are only passed to {@link compileAsync} and {@link
8 * compileStringAsync}, not {@link compile} or {@link compileString}.
9 *
10 * @typeParam sync - If this is `'sync'`, this can only be a `T`. If it's
11 * `'async'`, this can be either a `T` or a `Promise<T>`.
12 *
13 * @category Other
14 */
15export type PromiseOr<T, sync extends 'sync' | 'async'> = sync extends 'async'
16 ? T | Promise<T>
17 : T;