{"id":"a2b4d5202730e50a","repo":"sindresorhus/is","slug":"expected-value-which-is-bound-function-received","errorCode":null,"errorMessage":"Expected value which is `bound Function`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `bound Function`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1517,"sourceCode":"\t}\n}\n\nexport function assertBlob(value: unknown, message?: string): asserts value is Blob {\n\tif (!isBlob(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Blob', value));\n\t}\n}\n\nexport function assertBoolean(value: unknown, message?: string): asserts value is boolean {\n\tif (!isBoolean(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('boolean', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertBoundFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isBoundFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bound Function', value));\n\t}\n}\n\n/**\nNote: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n*/\nexport function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {\n\tif (!isBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}\n\nexport function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {\n\tif (!isClass(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Class', value));\n\t}\n}\n","sourceCodeStart":1499,"sourceCodeEnd":1535,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1499-L1535","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nassert.boundFunction(this.handleClick);\n// after\nthis.handleClick = this.handleClick.bind(this);\nassert.boundFunction(this.handleClick);","handlingStrategy":"validation","validationCode":"const bound = typeof fn === 'function' && !Object.prototype.hasOwnProperty.call(fn, 'prototype')\n  ? fn\n  : fn.bind(receiver);","typeGuard":"function isBoundFunction(value: unknown): value is Function {\n  return typeof value === 'function' && !Object.prototype.hasOwnProperty.call(value, 'prototype');\n}","tryCatchPattern":"try {\n  assert.boundFunction(fn);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // pass an arrow function or fn.bind(this) instead of a bare method reference\n  } else throw error;\n}","preventionTips":["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"],"tags":["type-assertion","function-binding","this-context"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}