Skip to content

isFunction() function

Checks if value is a function.

As a type guard it extracts the function members from a union type, so number | (() => void) is narrowed to () => void.

Signature:

typescript
isFunction: <T>(input: T) => input is Extract<T, FunctionLike> extends never ? T & FunctionLike : Extract<T, FunctionLike>

Example

ts
isFunction(() => null); // true
isFunction(function () {}); // true
isFunction(class A {}); // true
isFunction({}); // false
isFunction(null); // false
isFunction("function"); // false

Open Source Code

Released under the Apache-2.0 License.