debugtypescripteslintModeratepending
Debug: ESLint 'Parsing error: Unexpected token' with TypeScript
Viewed 0 times
eslintparsing-errortypescript-eslintparserconfig
Error Messages
Problem
ESLint throws parsing errors on TypeScript syntax (type annotations, interfaces, generics) even though TypeScript compiles fine.
Solution
ESLint needs a TypeScript parser:
npm install -D typescript-eslint
// eslint.config.js
import tseslint from 'typescript-eslint';
export default tseslint.config(
...tseslint.configs.recommended,
);
npm install -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
// .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"]
}
{
"parserOptions": {
"project": "./tsconfig.json"
}
}
// tsconfig.json
{ "include": ["src//", "tests//"] }
Cmd+Shift+P > ESLint: Restart ESLint Server
- For ESLint v9+ (flat config):
npm install -D typescript-eslint
// eslint.config.js
import tseslint from 'typescript-eslint';
export default tseslint.config(
...tseslint.configs.recommended,
);
- For ESLint v8 (.eslintrc):
npm install -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
// .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"]
}
- If using project references (tsconfig.json):
{
"parserOptions": {
"project": "./tsconfig.json"
}
}
- Common fix: ensure file is included in tsconfig:
// tsconfig.json
{ "include": ["src//", "tests//"] }
- VSCode: restart ESLint server after config changes:
Cmd+Shift+P > ESLint: Restart ESLint Server
Revisions (0)
No revisions yet.