Skip to content

Enhancement: [consistent-type-imports] prevent type-only imports from using inline type specifiers #6338

@latin-1

Description

@latin-1

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/consistent-type-imports

Description

With "importsNotUsedAsValues": "error" in tsconfig.json, those two lines behave differently.

import type { T } from "./module"; // ok
import { type T } from "./module"; // error ts(1371)

While using the rule consistent-type-imports with option "fixStyle": "inline-type-imports", this plugin will yield incorrect ts code.

// before
import { T } from "./module";

// after
import { type T } from "./module"; // error ts(1371)

We may need a new option or a new rule to handle the type-only imports properly.

import { type T }         -> import type { T }
import { type A, type B } -> import type { A, B }
import { A, type B }      -> <as-is>
import { A, B }           -> <as-is>

Fail

import { type T }
import { type A, type B }

Pass

import type { T }
import type { A, B }
import { A, type B }
import { A, B }

Additional Info

microsoft/TypeScript#47118

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions