logoESLint React
Getting Started

TypeScript with alternative parser

Getting started with TypeScript + TS Blank ESLint Parser setup

The ts-blank-eslint-parser is a work in progress and comes with limitations:

  • No support for TypeScript syntax that need transformation like enums, namespaces, decorators
  • No support for rules that require type information
  • No fixable support for types (the types will also be stripped out in the fix output)

Use it only if you are okay with the limitations.

Install

Terminal
# npm
npm install --save-dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin@next
 
# pnpm
pnpm add --save-dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin@next
 
# yarn
yarn add --dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin@next

Setup

eslint.config.js
// @ts-check
import eslintJs from "@eslint/js";
import eslintReact from "@eslint-react/eslint-plugin";
import { isInEditorEnv } from "@eslint-react/shared";
import tsBlankEslintParser from "ts-blank-eslint-parser";
import tseslint from "typescript-eslint";
import globals from "globals";
 
const GLOB_TS = ["**/*.ts", "**/*.tsx"];
 
function getOptimalParserConfig(project = "tsconfig.json") {
  switch (true) {
    case isInEditorEnv():
    case process.argv.includes("--fix"):
      return {
        parser: tseslint.parser,
        parserOptions: {
          project,
          tsconfigRootDir: import.meta.dirname,
        },
      };
  }
  return { parser: tsBlankEslintParser };
}
 
export default [
  // base configuration for browser environment source files
  {
    files: GLOB_TS,
    languageOptions: {
      globals: {
        ...globals.browser,
      },
      ...getOptimalParserConfig(),
    },
    rules: {
      ...eslintJs.configs.recommended.rules,
    },
  },
  // React configuration
  {
    files: GLOB_TS,
    ...eslintReact.configs.recommended,
  },
];

On this page