/** * Wrap a type or the return type of `T` in a promise. If the type is already a * promise, the type is returned as-is. This is useful for dynamically wrapping * a function, a value, or a promise without inadvertedly nesting promises. * * @template T The type to wrap. * @example * // Wrap a type in a promise. * PromiseWrap // Promise * * // Keep a promise as-is. * PromiseWrap> // Promise * * // Wrap the return type of a function in a promise. * PromiseWrap<() => number> // () => Promise * * // Extract the return type of an async function as-is. * PromiseWrap<() => Promise> // () => Promise */ type PromiseWrap = T extends Promise ? T : T extends (...parameters: infer P) => infer U ? (...parameters: P) => U extends Promise ? U : Promise : Promise; export type { PromiseWrap };