ianstormtaylor/slate · error · Error
Got non-numeric path index
Error message
Got non-numeric path index
What it means
Path.common() computes the shared prefix of two paths by pairwise comparing segments; every segment must be a number. One of the paths contained a non-numeric segment (string, undefined, etc.), so the comparison cannot proceed.
Source
Thrown at packages/slate/src/interfaces/path.ts:203
if (reverse) {
paths = paths.slice(1)
} else {
paths = paths.slice(0, -1)
}
return paths
},
common(path: Path, another: Path): Path {
const common: Path = []
for (let i = 0; i < path.length && i < another.length; i++) {
const av = path[i]
const bv = another[i]
if (typeof av !== 'number' || typeof bv !== 'number') {
throw new Error('Got non-numeric path index')
}
if (av !== bv) {
break
}
common.push(av)
}
return common
},
compare(path: Path, another: Path): -1 | 0 | 1 {
const min = Math.min(path.length, another.length)
for (let i = 0; i < min; i++) {
if (path[i] < another[i]) return -1
if (path[i] > another[i]) return 1View on GitHub (pinned to 72a37c701e)
Solutions
- Coerce external paths: const p = raw.split('.').map(Number) before use.
- Type both arguments as Path and construct paths only via Path APIs or numeric array operations.
- Add a runtime guard: path.every(n => Number.isInteger(n)) before calling Path.common.
- Fix upstream bugs where an index is computed with string ops or where optional access yields undefined.
Example fix
// before
const common = Path.common(pathA.split('.'), pathB) // string segments!
// after
const common = Path.common(pathA.split('.').map(Number) as Path, pathB) Defensive patterns
Strategy: type-guard
Validate before calling
const ok = [a, b].every(p => p.every(n => Number.isInteger(n)))
if (!ok) { /* reject */ } Type guard
const isPath = (p: unknown): p is Path => Array.isArray(p) && p.every(n => Number.isInteger(n))
Prevention
- Coerce split-string paths with .map(Number).
- Keep both operands typed as Path.
When it happens
Trigger: Calling Path.common(pathA, pathB) where either array contains a string index, undefined, or null; paths assembled from serialized strings or unvalidated external data; one path being undefined itself and index access yielding undefined.
Common situations: Persisting/loading paths (localStorage, server, URL) as strings like '0.1' and splitting without converting to numbers; mixing path types after JSON round-trips; a variable typed any shadowing a real Path.
Related errors
- Got non-numeric path index
- Cannot get the relative path of [${path}] inside ancestor [$
- Unable to find the path for Slate node: ${Scrubber.stringify
- Cannot get the next node from the root node!
- Cannot get the previous node from the root node!
AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27).
Data as JSON: /api/errors/00910fb35b11f929.
Report an issue: GitHub.