function - nberlette/is GitHub Wiki
function isFunction<T extends FunctionOrConstructor>(
it: T | unknowns,
): it is FunctionOrConstructor<any, any, any> extends T ? Function : T;
Check if the given value is a function.
Name | Info |
---|---|
it |
The value to check. |
true
if the value is a function, false
otherwise.
Standard
import { isFunction } from "jsr:@nick/is/function";
console.log(isFunction(() => {})); // true
console.log(isFunction(function () {})); // true
console.log(isFunction(class {})); // true
console.log(isFunction(new Function())); // true
console.log(isFunction({})); // false
console.log(isFunction(1)); // false
function isFunction<T = any, A extends readonly any[] = any[]>(
it: Fn<T, A> | unknowns,
): it is Fn<T, A>;
function isFunction<T = any, A extends readonly any[] = any[], R = any>(
it: ThisFn<T, A, R> | unknowns,
): it is ThisFn<T, A, R>;
function isFunction(it: unknown): it is Function;
function isFunction(it: unknown): it is FunctionOrConstructor;
export type Fn<T = any, A extends readonly any[] = any[]> = (...args: A) => T;
-
T
(default:any
) -
A
extendsreadonly any[]
(default:any[]
)
export type FunctionOrConstructor<
T = any,
A extends readonly any[] = any[],
R = void,
> = Constructor<R, A> | Fn<R, A> | ThisFn<T, A, R> | Function;
-
T
(default:any
) -
A
extendsreadonly any[]
(default:any[]
) -
R
(default:void
)
export type ThisFn<T = any, A extends readonly any[] = any[], R = any> = (
this: T,
...args: A
) => R;
-
T
(default:any
) -
A
extendsreadonly any[]
(default:any[]
) -
R
(default:any
)