- Error
- Reported by the lexer and parser
TS1127
Invalid character.
The source contains a character that cannot appear there, such as a stray symbol or an escape that produces an invalid identifier character.
What it means
The lexer found a character that isn't valid in TypeScript source at that position. Common causes are characters pasted from documents (smart quotes, symbols) and \u escapes inside an identifier that produce a character identifiers can't contain, such as a space.
Example
const x\u0020y = 1;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(1,8): error TS1127: Invalid character.
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
- Delete or replace the character; retype quotes and operators by hand if the code was pasted.
- Inside identifiers, only use escapes for letters, digits,
$and_.