sindresorhus/is · error · TypeError
Expected value which is `bound Function`, received value of
Error message
Expected value which is `bound Function`, received value of type `${is(value)}`. What it means
Thrown by `assertBoundFunction()` when the value fails `isBoundFunction` — i.e., it is not a function, or it is a function that still has a `prototype` property (bound functions and arrow functions lack `prototype`). The library uses the prototype-absence heuristic to detect functions safe to call detached from a receiver.
Source
Thrown at source/index.ts:1517
}
}
export function assertBlob(value: unknown, message?: string): asserts value is Blob {
if (!isBlob(value)) {
throw new TypeError(message ?? typeErrorMessage('Blob', value));
}
}
export function assertBoolean(value: unknown, message?: string): asserts value is boolean {
if (!isBoolean(value)) {
throw new TypeError(message ?? typeErrorMessage('boolean', value));
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function assertBoundFunction(value: unknown, message?: string): asserts value is Function {
if (!isBoundFunction(value)) {
throw new TypeError(message ?? typeErrorMessage('bound Function', value));
}
}
/**
Note: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)
*/
export function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {
if (!isBuffer(value)) {
throw new TypeError(message ?? typeErrorMessage('Buffer', value));
}
}
export function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {
if (!isClass(value)) {
throw new TypeError(message ?? typeErrorMessage('Class', value));
}
}
View on GitHub ↗ (pinned to 7821031c66)
Solutions
- Bind the method before passing it: `this.method.bind(this)` (typically in the constructor).
- Use a class-field arrow function (`handleClick = () => {...}`) which has no prototype and passes the check.
- Wrap in an arrow at the call site: `() => obj.method()`.
- If the callback genuinely doesn't need `this`, define it as an arrow function.
Example fix
// before assert.boundFunction(this.handleClick); // after this.handleClick = this.handleClick.bind(this); assert.boundFunction(this.handleClick);
Defensive patterns
Strategy: validation
Validate before calling
const bound = typeof fn === 'function' && !Object.prototype.hasOwnProperty.call(fn, 'prototype') ? fn : fn.bind(receiver);
Type guard
function isBoundFunction(value: unknown): value is Function {
return typeof value === 'function' && !Object.prototype.hasOwnProperty.call(value, 'prototype');
} Try / catch
try {
assert.boundFunction(fn);
} catch (error) {
if (error instanceof TypeError) {
// pass an arrow function or fn.bind(this) instead of a bare method reference
} else throw error;
} Prevention
- Bound-ness is detected by the absence of an own prototype property — arrow functions and .bind() results qualify; ordinary function declarations do not
- Never pass obj.method directly as a callback; pass () => obj.method() or obj.method.bind(obj)
- Bind methods once in the constructor (or use class fields with arrow functions) rather than at each call site
When it happens
Trigger: Calling `assert.boundFunction(fn)` with an ordinary function declaration/expression or a class method reference that was never `.bind()`ed. Note arrow functions PASS this check (they also lack `prototype`), so the failure is specifically un-bound normal/class functions or non-functions.
Common situations: Passing `this.handleClick` straight from a class without binding in the constructor; registering plain named functions as callbacks where the API demands pre-bound handlers; refactoring an arrow-function property into a method and losing bound-ness.
Related errors
- Expected value which is `Array`, received value of type `${i
- Expected value which is `ArrayBuffer`, received value of typ
- Expected value which is `array-like`, received value of type
- Expected value which is `AsyncFunction`, received value of t
- Expected value which is `AsyncGenerator`, received value of
AI-assisted analysis of sindresorhus/is@7821031c66 (2026-07-31).
Data as JSON: /data/errors/a2b4d5202730e50a.json.
Report an issue: GitHub ↗.