{"record":{"id":"c2e7643346aa302d","repo":"jestjs/jest","slug":"pkg-name-typeof-type-is-not-a-function","errorCode":null,"errorMessage":"${pkg}: ${name} typeof ${type} is not a function","messagePattern":"(.+?): (.+?) typeof (.+?) is not a function","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/diff-sequences/src/index.ts","lineNumber":774,"sourceCode":"  }\n};\n\nconst validateLength = (name: string, arg: unknown) => {\n  if (typeof arg !== 'number') {\n    throw new TypeError(`${pkg}: ${name} typeof ${typeof arg} is not a number`);\n  }\n  if (!Number.isSafeInteger(arg)) {\n    throw new RangeError(`${pkg}: ${name} value ${arg} is not a safe integer`);\n  }\n  if (arg < 0) {\n    throw new RangeError(`${pkg}: ${name} value ${arg} is a negative integer`);\n  }\n};\n\nconst validateCallback = (name: string, arg: unknown) => {\n  const type = typeof arg;\n  if (type !== 'function') {\n    throw new TypeError(`${pkg}: ${name} typeof ${type} is not a function`);\n  }\n};\n\n// Compare items in two sequences to find a longest common subsequence.\n// Given lengths of sequences and input function to compare items at indexes,\n// return by output function the number of adjacent items and starting indexes\n// of each common subsequence.\nexport default function diffSequence(\n  aLength: number,\n  bLength: number,\n  isCommon: IsCommon,\n  foundSubsequence: FoundSubsequence,\n): void {\n  validateLength('aLength', aLength);\n  validateLength('bLength', bLength);\n  validateCallback('isCommon', isCommon);\n  validateCallback('foundSubsequence', foundSubsequence);\n","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/diff-sequences/src/index.ts#L756-L792","documentation":"diff-sequences requires two callbacks: isCommon(indexA, indexB) and foundSubsequence(nCommon, aCommon, bCommon). validateCallback throws a TypeError if either is not a function, because the algorithm calls them during traversal and a non-function would otherwise crash deeper in the stack with a less helpful message.","triggerScenarios":"Calling diffSequence with a non-function for isCommon or foundSubsequence — e.g. passing an object, undefined, or forgetting the argument. Also when a callback is destructured/renamed incorrectly and ends up undefined.","commonSituations":"Copying a diff-sequences example and dropping one of the two callbacks; passing a method reference that lost its `this` binding and is actually undefined after destructuring; integrating from loosely-typed JS.","solutions":["Supply both required function arguments: `diffSequence(aLen, bLen, isCommon, foundSubsequence)` where the last two are functions.","Verify the function references are defined at the call site (watch for typos and lost `this`).","If a callback is optional in your wrapper, pass a no-op: `() => true` for isCommon or `() => {}` for foundSubsequence."],"exampleFix":"// before\ndiffSequence(a.length, b.length, isCommon); // missing foundSubsequence -> undefined\n\n// after\ndiffSequence(a.length, b.length, isCommon, (n, aIdx, bIdx) => {\n  console.log('common run of', n, 'at', aIdx, bIdx);\n});","handlingStrategy":"type-guard","validationCode":"import diffSequence from '@jest/diff-sequences';\n\nfunction runDiff(aLen, bLen, isCommon, found) {\n  if (typeof isCommon !== 'function') throw new TypeError('isCommon must be a function');\n  if (typeof found !== 'function') throw new TypeError('foundSubsequence must be a function');\n  return diffSequence(aLen, bLen, isCommon, found);\n}","typeGuard":"function isFunction(v: unknown): v is (...args: any[]) => any {\n  return typeof v === 'function';\n}\n\nif (!isFunction(isCommon) || !isFunction(foundSubsequence)) {\n  throw new TypeError('callbacks must be functions');\n}","tryCatchPattern":null,"preventionTips":["Supply both callbacks explicitly; provide no-ops if one is unused.","Watch for lost `this` when passing method references — bind or wrap them.","Let TypeScript's signature guide you; avoid `any` so missing args are caught."],"tags":["diff-sequences","input-validation","typeerror","callbacks"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}