• Error
  • Reported by the type checker

TS2413

'{0}' index type '{1}' is not assignable to '{2}' index type '{3}'.

A number index signature's type doesn't fit the string index signature of the same type. Make the number index type a subtype of the string one.

What it means

Numeric keys are also string keys in JavaScript, so a type with both index signatures needs the number signature's value type to be assignable to the string signature's value type.

Example

index.ts
export interface Table {
  [key: string]: number;
  [index: number]: string;
}
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(3,3): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'.

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

  • Make the number index type assignable to the string index type (here both number, or the string one number | string).
  • Drop one of the signatures if both kinds of key should hold the same type.