{"id":"a9d9eec7cf169f88","repo":"sindresorhus/is","slug":"expected-value-which-is-function-received-value","errorCode":null,"errorMessage":"Expected value which is `Function`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Function`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1641,"sourceCode":"\t}\n}\n\nexport function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array {\n\tif (!isFloat64Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Float64Array', value));\n\t}\n}\n\nexport function assertFormData(value: unknown, message?: string): asserts value is FormData {\n\tif (!isFormData(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('FormData', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Function', value));\n\t}\n}\n\nexport function assertGenerator(value: unknown, message?: string): asserts value is Generator {\n\tif (!isGenerator(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Generator', value));\n\t}\n}\n\nexport function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction {\n\tif (!isGeneratorFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('GeneratorFunction', value));\n\t}\n}\n\nexport function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement {\n\tif (!isHtmlElement(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('HTMLElement', value));","sourceCodeStart":1623,"sourceCodeEnd":1659,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1623-L1659","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before\nrunTask({onComplete: handleDone()}); // passes the return value\n// after\nrunTask({onComplete: handleDone});","handlingStrategy":"type-guard","validationCode":"if (typeof value !== 'function') {\n  throw new TypeError(`Expected function, got ${typeof value}`);\n}","typeGuard":"function isFunction(value: unknown): value is (...args: unknown[]) => unknown {\n  return typeof value === 'function';\n}","tryCatchPattern":"try {\n  assert.function(callback);\n} catch (error) {\n  if (error instanceof TypeError) { /* caller passed a non-callable; report config error */ }\n  else throw error;\n}","preventionTips":["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"],"tags":["callback","type-assertion","runtime-validation","javascript"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}