- Error
- Reported by the lexer and parser
TS17006
An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.
A unary operator like `-x` is on the left of `**`. Add parentheses: `(-x) ** 2`.
What it means
JavaScript doesn't allow a unary operator (-, +, !, ~, typeof, void, delete, await) directly on the left-hand side of **, because -2 ** 2 would be ambiguous. ts-r's parser reports it; the message names the operator.
Example
declare const x: number;
export const y = -x ** 2;
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,18): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.
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
- Add parentheses for the meaning you want:
(-x) ** 2or-(x ** 2).