Skip to content

Proposal for new rule - consistent style for type-only imports #2200

@nojvek

Description

@nojvek

Proposal

{
  "rules": {
    "@typescript-eslint/prefer-import-type": ["error"]
  }
}
// your repro code case
import {FooBar} from 'foo-bar';
const foo: FooBar = {foo: 1, bar: 2};

Expected Result
FooBar is only being used as a type, import as 'import type {FooBar}'

Actual Result

Additional Info

Since typescript now supports import type {X} for type only imports that don't get emitted in js, nor do get counted as cyclic imports, it would be nice to have typescript-eslint automatically flag and fix import {T} to import type {T}

If you're willing to accept the suggestion, I'm happy to create a PR and land this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy