- Error
- Reported by the lexer and parser
TS1011
An element access expression should take an argument.
An element access (`x[...]`) has nothing inside the brackets. Put the index or key between the brackets.
What it means
Square brackets after an expression read an element or property, so they need an expression inside: an index, a key, or a variable holding one. Empty brackets [] after a value are only valid in types (string[]), not in expressions.
Example
const items = [1, 2, 3];
const first = items[];
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,21): error TS1011: An element access expression should take an argument.
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
- Write the index or key:
items[0]. - If you meant an array type, move it to a type position:
const items: number[] = [].