{"record":{"id":"0cdef8d190fc9c97","repo":"jestjs/jest","slug":"pkg-name-typeof-typeof-arg-is-not-a-numb","errorCode":null,"errorMessage":"${pkg}: ${name} typeof ${typeof arg} is not a number","messagePattern":"(.+?): (.+?) typeof (.+?) is not a number","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/diff-sequences/src/index.ts","lineNumber":761,"sourceCode":"    // Recursely find and return common subsequences following the division.\n    findSubsequences(\n      nChangeFollowing,\n      aStartFollowing,\n      aEnd,\n      bStartFollowing,\n      bEnd,\n      transposed,\n      callbacks,\n      aIndexesF,\n      aIndexesR,\n      division,\n    );\n  }\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,","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/diff-sequences/src/index.ts#L743-L779","documentation":"@jest/diff-sequences validates its inputs before computing a longest common subsequence. validateLength throws a TypeError when aLength or bLength is not of type 'number' (e.g. undefined, a string, an object). The check runs for both length arguments before any diffing work, so the function fails fast on misuse rather than producing a nonsensical result.","triggerScenarios":"Calling diffSequence(aLength, bLength, isCommon, foundSubsequence) where one of the length arguments is undefined, null, a string, or any non-number — for example passing the array itself instead of its `.length`, or forgetting an argument.","commonSituations":"Passing arrays/objects where a numeric length is expected; computing a length from an optional field that is undefined; integrating diff-sequences with untyped JS that supplies the wrong shape; off-by-one in argument order when copying an example.","solutions":["Pass the numeric length of each sequence, not the sequence itself: `diffSequence(a.length, b.length, ...)`.","Ensure the length value is actually defined at the call site (guard optional inputs with a default of 0).","If you have unknown inputs, coerce/validate with Number.isInteger before calling."],"exampleFix":"// before\ndiffSequence(arrA, arrB, isCommon, foundSubsequence); // passed arrays, not lengths\n\n// after\ndiffSequence(arrA.length, arrB.length, isCommon, foundSubsequence);","handlingStrategy":"type-guard","validationCode":"import diffSequence from '@jest/diff-sequences';\n\nfunction safeDiff(aLen, bLen, isCommon, found) {\n  if (typeof aLen !== 'number' || typeof bLen !== 'number') {\n    throw new TypeError('lengths must be numbers');\n  }\n  return diffSequence(aLen, bLen, isCommon, found);\n}","typeGuard":"function isNumber(v: unknown): v is number {\n  return typeof v === 'number';\n}\n\n// usage:\nif (!isNumber(aLen) || !isNumber(bLen)) {\n  throw new TypeError('aLength and bLength must be numbers');\n}\ndiffSequence(aLen, bLen, isCommon, found);","tryCatchPattern":null,"preventionTips":["Always pass `.length` of sequences, never the sequences themselves.","Default optional lengths to 0 rather than leaving them undefined.","In TypeScript, rely on the typed signature rather than `any` to catch this at compile time."],"tags":["diff-sequences","input-validation","typeerror","api-misuse"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}