• Error
  • Reported by the lexer and parser

TS17007

A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.

A type assertion `<T>x` is on the left of `**`. Add parentheses around it.

What it means

An angle-bracket type assertion (<number>x) directly on the left-hand side of ** isn't allowed, for the same reason as unary operators (TS17006). ts-r's parser reports it.

Example

index.ts
declare const x: unknown;
export const y = <number>x ** 2;
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,18): error TS17007: A type assertion expression 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

  • Wrap the assertion in parentheses: (<number>x) ** 2, or use as: (x as number) ** 2.