• Error
  • Reported by the type checker

TS2493

Tuple type '{0}' of length '{1}' has no element at index '{2}'.

A tuple is indexed past its last element. Use an index that exists, or change the tuple type to include the element.

What it means

A tuple type has a fixed length. Reading a constant index that is beyond that length can only give undefined, so it is reported.

Example

index.ts
const point: [number, number] = [1, 2];
export const z = point[2];
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,24): error TS2493: Tuple type '[number, number]' of length '2' has no element at index '2'.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Use an index within the tuple's length.
  • If the element can exist, add it to the type: [number, number, number?].
  • Use an array type (number[]) if the length really varies.