sindresorhus/is · error · TypeError
Expected value which is `Function`, received value of type `
Error message
Expected value which is `Function`, received value of type `${is(value)}`. What it means
Thrown by `assertFunction()` when `isFunction()` (a `typeof value === 'function'` check) fails. It's used to guarantee a value is callable before invoking it, and reports the actual type of what was received.
Source
Thrown at source/index.ts:1641
}
}
export function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {
if (!isFloat64Array(value)) {
throw new TypeError(message ?? typeErrorMessage('Float64Array', value));
}
}
export function assertFormData(value: unknown, message?: string): asserts value is FormData {
if (!isFormData(value)) {
throw new TypeError(message ?? typeErrorMessage('FormData', value));
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function assertFunction(value: unknown, message?: string): asserts value is Function {
if (!isFunction(value)) {
throw new TypeError(message ?? typeErrorMessage('Function', value));
}
}
export function assertGenerator(value: unknown, message?: string): asserts value is Generator {
if (!isGenerator(value)) {
throw new TypeError(message ?? typeErrorMessage('Generator', value));
}
}
export function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {
if (!isGeneratorFunction(value)) {
throw new TypeError(message ?? typeErrorMessage('GeneratorFunction', value));
}
}
export function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement {
if (!isHtmlElement(value)) {
throw new TypeError(message ?? typeErrorMessage('HTMLElement', value));View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Check the call site: pass the function reference (`fn`), not its result (`fn()`), and verify the option/property name spelling.
- Confirm the callback is actually provided by the caller; make it required in the signature or supply it explicitly.
- If the callback is genuinely optional, guard with `if (is.function_(cb))` instead of asserting.
Example fix
// before
runTask({onComplete: handleDone()}); // passes the return value
// after
runTask({onComplete: handleDone}); Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof value !== 'function') {
throw new TypeError(`Expected function, got ${typeof value}`);
} Type guard
function isFunction(value: unknown): value is (...args: unknown[]) => unknown {
return typeof value === 'function';
} Try / catch
try {
assert.function(callback);
} catch (error) {
if (error instanceof TypeError) { /* caller passed a non-callable; report config error */ }
else throw error;
} Prevention
- Check `typeof value === 'function'` before invoking callbacks from options objects
- Don't pass the result of calling a function (`fn()`) where the function itself (`fn`) is expected
- Type callback parameters precisely in signatures so TypeScript flags non-callables at compile time
When it happens
Trigger: `is.assert.function_(value)` called with a non-callable value — commonly `undefined` from a missing callback option, a string naming a function, or the result of calling the function instead of passing its reference.
Common situations: Options objects where a callback key is misspelled or omitted (`onDone` vs `onComplete`); passing `fn()` (the invocation result) instead of `fn`; destructuring a method off an object where it doesn't exist; API changes that renamed a hook between library versions.
Related errors
- Expected value which is `falsy`, received value of type `${i
- Expected value which is `Array`, received value of type `${i
- Expected value which is `array-like`, received value of type
- Expected value which is `BigUint64Array`, received value of
- Expected value which is `empty map`, received value of type
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/a9d9eec7cf169f88.json.
Report an issue: GitHub ↗.