export type MaybeAsync = Promise | T; export const isPromise = (test: any) => test && typeof test.then === "function"; export const executeMaybeAsyncFunction = async ( func: (...args: any[]) => MaybeAsync, ...args: any[] ) => { let result = func(...args); if (isPromise(result)) { result = await result; } return result; };