---
title: "TypeScript"
description: "TypeScript parsing, strict rules, type-aware linting and erasable-syntax-only mode."
canonical_url: "https://vinicunca.dev/eslint/configuration/typescript"
---
# TypeScript

> TypeScript parsing, strict rules, type-aware linting and erasable-syntax-only mode.

TypeScript support is **on** when `typescript` or `@typescript/native-preview` is installed. You don't need to set `typescript: true` in a typical project.

```js [eslint.config.js]
import { vinicuncaESLint } from '@vinicunca/eslint-config';

export default vinicuncaESLint();
```

Turn it off, or pass an object, when you need to:

```js [eslint.config.js]
export default vinicuncaESLint({
  typescript: false,
});
```

## Parser and files

`@typescript-eslint/parser` is used for `*.ts`, `*.tsx`, `*.mts`, `*.cts` and any [`componentExts`](https://vinicunca.dev/eslint/configuration/options) (`.vue` is added automatically when Vue is on). Config names: `vinicunca/typescript/setup`, `vinicunca/typescript/parser`, `vinicunca/typescript/rules`.

The plugin prefix is `ts/*` (renamed from `@typescript-eslint`).

## Rules worth knowing

The config starts from TypeScript ESLint's `eslint-recommended` and `strict` sets, then changes several:

- `ts/array-type`: `Array<T>` (not `T[]`)
- `ts/consistent-type-definitions`: `interface` over `type`
- `ts/consistent-type-imports`: `import type` with `separate-type-imports`
- `ts/method-signature-style`: property syntax (`fn: () => void`)
- `ts/no-explicit-any` is **off**
- `ts/no-non-null-assertion` is **off**
- Unused variables allow a `_` prefix

With [`type: 'lib'`](https://vinicunca.dev/eslint/configuration/options#general), `ts/explicit-function-return-type` is also on (expressions, higher-order functions and IIFEs are allowed).

## Type-aware rules

Set `tsconfigPath` to enable typed linting. The parser uses TypeScript's project service with that file as `defaultProject`:

```js [eslint.config.js]
export default vinicuncaESLint({
  typescript: {
    tsconfigPath: 'tsconfig.json',
  },
});
```

That adds `vinicunca/typescript/type-aware-parser` and `vinicunca/typescript/rules-type-aware`, including:

`ts/await-thenable`, `ts/no-floating-promises`, `ts/no-misused-promises`, `ts/no-unsafe-*`, `ts/restrict-template-expressions`, `ts/strict-boolean-expressions` (nullable booleans and objects allowed), `ts/switch-exhaustiveness-check`, `ts/return-await` (`in-try-catch`), and others.

> [!TIP]
> 
> Type-aware rules are slower. Exclude generated files with `ignoresTypeAware`, and keep Markdown / Astro virtual files out (already the default).

**tsconfigPath** (`string`): Path to tsconfig.json. Setting it turns type-aware rules on.

**overrides** (`Rules`): Overrides for vinicunca/typescript/rules.

**overridesTypeAware** (`Rules`): Overrides for vinicunca/typescript/rules-type-aware. Ignored unless tsconfigPath is set.

**filesTypeAware** (`string[]`): Defaults to ['**/*.?([cm])ts', '**/*.?([cm])tsx'].

**ignoresTypeAware** (`string[]`): Defaults to ['**/*.md/**', '**/*.astro/*.ts'].

**parserOptions** (`Partial<ParserOptions>`): Extra @typescript-eslint/parser options, merged last.

React's `react/no-leaked-conditional-rendering` and Solid's typed parser also follow `tsconfigPath`. See [Frameworks](https://vinicunca.dev/eslint/configuration/frameworks).

## Erasable syntax only

For Node.js type stripping (or other pipelines that erase types), forbid syntax that cannot be erased:

```js [eslint.config.js]
export default vinicuncaESLint({
  typescript: {
    erasableOnly: true,
  },
});
```

Enables [eslint-plugin-erasable-syntax-only](https://github.com/JoshuaKGoldberg/eslint-plugin-erasable-syntax-only) (bundled) for enums, namespaces, parameter properties, and import/export aliases. Config name: `vinicunca/typescript/erasable-syntax-only`.


## Sitemap

See the full [sitemap](https://vinicunca.dev/sitemap.md) for all pages.
