1.38.0isFunction
Checks whether a value is a function and provides a TypeScript type guard for function narrowing.
isFunction(value):value is (...args: never[]) => unknownImplementation
The function uses JavaScript's typeof operator and checks whether the result is exactly "function".
Type guard
The return type `value is (...args: never[]) => unknown` makes the function a TypeScript type guard. A successful check narrows the value to a callable function type.
typeof behavior
The check follows JavaScript's typeof semantics. This means callable values such as regular functions, arrow functions, async functions, and classes are reported as functions.
Parameters
valueunknownrequiredThe value to check.
Returns
value is (...args: never[]) => unknownReturns true when the value is a function; otherwise returns false. When true, TypeScript narrows the value to a callable function type.
Examples
Basic usage
Check whether a value is a function.
isFunction(() => {});
// true
isFunction("hello");
// falseType narrowing
The type guard narrows an unknown value to a callable function type.
const value: unknown = () => "hello";
if (isFunction(value)) {
value();
// value is narrowed to (...args: never[]) => unknown
}Named functions
Regular named functions are recognized as functions.
function greet() {
return "Hello";
}
isFunction(greet);
// trueAsync functions
Async functions are also recognized because typeof returns "function".
async function loadData() {
return "data";
}
isFunction(loadData);
// trueClasses
JavaScript classes are also reported as functions by typeof.
class User {}
isFunction(User);
// trueNon-functions
Objects, strings, numbers, null, and undefined return false.
isFunction({});
// false
isFunction(42);
// false
isFunction(null);
// false
isFunction(undefined);
// false