- Error
- Reported by the type checker
TS2464
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
A computed property name has a type that can't be a property key. Use a string, number or symbol expression.
What it means
Property keys in JavaScript are strings, numbers (converted to strings) or symbols. A computed name [expr] in an object literal or class whose type is something else, such as an object or a boolean, is reported.
Example
const key = { id: 1 };
export const table = { [key]: "row" };
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,24): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
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 a string, number or symbol for the key:
[key.id]or[String(key.id)]. - If you need object keys, use a
Mapinstead of an object literal.