Skip to main content

no-import-type-side-effects

Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

The --verbatimModuleSyntax compiler option causes TypeScript to do simple and predictable transpilation on import declarations. Namely, it completely removes import declarations with a top-level type qualifier, and it removes any import specifiers with an inline type qualifier.

The latter behavior does have one potentially surprising effect in that in certain cases TS can leave behind a "side effect" import at runtime:

import { type A, type B } from 'mod';

// is transpiled to

import {} from 'mod';
// which is the same as
import 'mod';

For the rare case of needing to import for side effects, this may be desirable - but for most cases you will not want to leave behind an unnecessary side effect import.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-import-type-side-effects": "error"
}
};
Try this rule in the playground ↗

Examples

This rule enforces that you use a top-level type qualifier for imports when it only imports specifiers with an inline type qualifier

import { type A } from 'mod';
import { type A as AA } from 'mod';
import { type A, type B } from 'mod';
import { type A as AA, type B as BB } from 'mod';
Open in Playground

Options

This rule is not configurable.

When Not To Use It

  • If you want to leave behind side effect imports, then you shouldn't use this rule.
  • If you're not using TypeScript 5.0's verbatimModuleSyntax option, then you don't need this rule.

Resources