Toolbox-XToolbox-X
GuardsFunction Guards

Check Functions Returning Promises

Checks if a function returns a Promise.

isReturningPromise

Checks if a function returns a Promise. Identifies only async functions.

Import

import { isReturningPromise } from 'toolbox-x/guards';

Signature

function isReturningPromise<T>(fn: unknown): fn is AsyncFunction<T>

Type Definition

type AsyncFunction<T> = (...args: any) => Promise<T>;

Examples

playground.ts
// Type-safe handling
function wrapAsync(fn: unknown) {
  if (!isReturningPromise(fn)) {
    throw new Error('Function must return a Promise');
  }
  
  return async (...args: unknown[]) => {
    try {
      return await fn(...args);
    } catch (error) {
      console.error('Async error:', error);
      throw error;
    }
  };
}

Alias

Main ExportAlias Names
isReturningPromisedoesReturnPromise

Notes

  • Detects only async functions
  • Works with bound functions and methods

Last updated: Sun, May 31, 2026 05:02:11AM (UTC)

On this page