{"id":"38e5fd3fe2245c8d","repo":"jestjs/jest","slug":"jest-diff-sequences-name-typeof-type-is-no","errorCode":null,"errorMessage":"@jest/diff-sequences: ${name} typeof ${type} is not a function","messagePattern":"@jest/diff-sequences: (.+?) 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/f49721c78e195558b40913977c9230f5b7f559d8/packages/diff-sequences/src/index.ts#L756-L792","documentation":"diffSequence validates isCommon and foundSubsequence with validateCallback, requiring typeof === 'function'. The algorithm calls back into these functions to report matches; a non-function would throw a less helpful error mid-algorithm, so diff-sequences fails fast up front.","triggerScenarios":"Calling diffSequence with isCommon or foundSubsequence that is not a function: passing undefined (omitted arg), an arrow stored in a variable that was never assigned, an object/method reference that wasn't bound, or a string name of a method by mistake.","commonSituations":"Refactoring that drops the 4th argument; passing a method reference without binding; copy-paste leaving a placeholder null for a callback.","solutions":["Pass actual functions for both callbacks: an (aIndex, bIndex) => boolean isCommon and an (nCommon, aCommon, bCommon) => void foundSubsequence.","If forwarding callbacks, ensure they are defined and are functions before calling diffSequence.","Bind methods: `obj.callback.bind(obj)` rather than passing `obj.callback` unbound when `this` matters."],"exampleFix":"// before — 4th argument missing/undefined\ndiffSequence(a.length, b.length, (i, j) => a[i] === b[j]);\n\n// after\ndiffSequence(\n  a.length,\n  b.length,\n  (i, j) => a[i] === b[j],\n  (nCommon, aCommon, bCommon) => { console.log('match', {nCommon, aCommon, bCommon}); },\n);","handlingStrategy":"type-guard","validationCode":"if (typeof isCommon !== 'function' || typeof foundSubsequence !== 'function') {\n  throw new TypeError('diffSequence callbacks must be functions');\n}","typeGuard":"function isCallback(x: unknown): x is (...args: number[]) => unknown {\n  return typeof x === 'function';\n}","tryCatchPattern":"try {\n  diffSequence(aLength, bLength, isCommon, foundSubsequence);\n} catch (e) {\n  if (e instanceof TypeError && /is not a function/.test(e.message)) { /* default no-op or rebind */ }\n  throw e;\n}","preventionTips":["Type the callback parameters explicitly so missing args are compile errors.","Bind methods before passing them as callbacks when `this` is needed.","Default missing callbacks to explicit no-ops in your wrapper."],"tags":["diff-sequences","validation","type-error","callback"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}