- Error
- Reported by the type checker
TS2411
Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.
A property doesn't fit the type of an index signature in the same type. Change the property's type, or widen the index signature.
What it means
An index signature like [key: string]: number says every string-named property has that type, including the ones declared explicitly. A named property whose type isn't assignable to the index signature's type breaks that promise.
Example
export interface Scores {
[name: string]: number;
label: string;
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,3): error TS2411: Property 'label' of 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
- Widen the index signature:
[name: string]: number | string. - Or move the odd property out:
{ label: string; scores: Record<string, number> }.