{"record":{"id":"6eca571921fe7238","repo":"ianstormtaylor/slate","slug":"expected-index-to-be-a-number-6eca57","errorCode":null,"errorMessage":"Expected index to be a number","messagePattern":"Expected index to be a number","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/node.ts","lineNumber":277,"sourceCode":"    path: Path,\n    options: NodeAncestorsOptions = {}\n  ): Generator<NodeEntry<Ancestor>, void, undefined> {\n    for (const p of Path.ancestors(path, options)) {\n      const n = Node.ancestor(root, p)\n      const entry: NodeEntry<Ancestor> = [n, p]\n      yield entry\n    }\n  },\n\n  child(root: Node, index: number): Descendant {\n    if (Node.isText(root)) {\n      throw new Error(\n        `Cannot get the child of a text node: ${Scrubber.stringify(root)}`\n      )\n    }\n\n    if (typeof index !== 'number') {\n      throw new Error('Expected index to be a number')\n    }\n\n    const c = root.children[index] as Descendant\n\n    if (c == null) {\n      throw new Error(\n        `Cannot get child at index \\`${index}\\` in node: ${Scrubber.stringify(\n          root\n        )}`\n      )\n    }\n\n    return c\n  },\n\n  *children(\n    root: Node,\n    path: Path,","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/node.ts#L259-L295","documentation":"Node.child(root, index) requires the index to be a number; passing anything else (undefined, a string, null) throws this error. It is a defensive type check for a JavaScript API that would otherwise silently return undefined.","triggerScenarios":"Calling Node.child(node, undefined) — commonly a destructuring or argument-count mistake; passing a string index from URL params or parsed JSON; calling child with a missing second argument.","commonSituations":"Refactors that drop or reorder the index argument; index variables shadowed/undefined; data-driven traversal where indices come from untyped sources.","solutions":["Check the index is a number before calling (Number.isInteger guard)","Fix the call site — the argument is likely undefined due to a missing/destructured variable","If indices come from external data, validate/coerce with Number() and reject NaN"],"exampleFix":"// before\nconst c = Node.child(node, idx) // idx is undefined\n\n// after\nconst c =\n  typeof idx === 'number' ? Node.child(node, idx) : null","handlingStrategy":"type-guard","validationCode":"if (Number.isInteger(index)) {\n  const c = Node.child(node, index)\n}","typeGuard":"const isValidIndex = (i) => Number.isInteger(i)","tryCatchPattern":null,"preventionTips":["Type the index parameter as number in TS signatures","Check for undefined indices from destructuring mistakes"],"tags":["slate","node-api","type-check","index","defensive"],"backgroundTag":"invalid-argument-type","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}