Skip to content

Instantly share code, notes, and snippets.

@CCColda
Created October 5, 2021 16:34
Show Gist options
  • Save CCColda/4251981e652164b4195ec78bcefbb8b7 to your computer and use it in GitHub Desktop.
Save CCColda/4251981e652164b4195ec78bcefbb8b7 to your computer and use it in GitHub Desktop.
/**
* @brief Gives the Promise + non-Promise variant of a function
* @example MaybePromise<(x: number, y: string | number) => Date> =
* ((x: number, y: string | number) => Date) | ((x: number, y: string | number) => Promise<Date>)
* @author COlda
*/
type MaybePromise<T extends (...args: any) => any> = T | (T extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : never);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment