Skip to content

AnyFunction type ​

A type for any function, for generic constraints such as F extends AnyFunction (safer than Function, which also accepts classes and has an untyped call).

ts
import type { AnyFunction } from 'utils';

Signature ​

ts
export type AnyFunction = (...arguments_: readonly never[]) => unknown;

Example ​

ts
function once<F extends AnyFunction>(fn: F): F;

Tests ​

Line coverage: 0 %.

  • ✅ accepts functions only

Source ​

src/types/any-function.ts (on GitHub)

Source code
ts
/**
 * A type for any function, for generic constraints such as `F extends AnyFunction` (safer than `Function`, which also
 * accepts classes and has an untyped call).
 *
 * @example
 * function once<F extends AnyFunction>(fn: F): F;
 */
export type AnyFunction = (...arguments_: readonly never[]) => unknown;
Test file
ts
import type { AnyFunction } from './any-function';

describe('AnyFunction', () => {
  it('accepts functions only', () => {
    expectTypeOf<(a: string) => number>().toExtend<AnyFunction>();
    expectTypeOf<string>().not.toExtend<AnyFunction>();
  });
});

Keywords: any, function, types, type

Generated from the JSDoc of the sources.