Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: consistent-type-imports should have an option to prevent cases with only inline type imports #6379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
me4502 opened this issue Jan 27, 2023 · 1 comment
Labels
external This issue is with another package, not typescript-eslint itself package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@me4502
Copy link

me4502 commented Jan 27, 2023

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

TypeScript 5.0 is introducing a new --verbatimModuleSyntax flag/option, that enforces type imports to output exactly as they are written, rather than letting the compiler decide. One of the noted output conditions of this is that import { type xyz } from "xyz"; will be rewritten to import "xyz";. This means inline type imports can and will still result in the file ending up imported. While this will always happen with this option enabled, it's also possible for it to happen currently if TypeScript decides to import it.

As this introduces potential unwanted imports, I propose a new option to disallow imports that purely contain inline type imports. The option could then add an auto-fixer to move the type import to the base of the import rather than inline. Eg, from import { type a } from './xyz'; -> import type { a } from './xyz';

Fail

import { type a, type x } from './xyz';

Pass

import { a, type b } from './xyz';

import type { b } from './xyz';

Additional Info

No response

@me4502 me4502 added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 27, 2023
@bradzacher
Copy link
Member

bradzacher commented Jan 27, 2023

consistent-type-imports is concerned with exactly one thing - ensuring your value imports are used as values, warning you when your value imports aren't used as values.
ESLint rules are best designed to handle one concern, rather than multiple.

What you're asking for here isn't related to ensuring type-only import specifiers are correctly annotated. Instead it's related to the semantics of how TS may elide import specifiers or import declarations based on the type specifier, and wanting to enforce that you don't accidentally emit a side-effect import.

There are existing lint rules that can help out here, such as import/consistent-type-specifier-style.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2023
@bradzacher bradzacher added external This issue is with another package, not typescript-eslint itself and removed triage Waiting for team members to take a look enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Jan 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external This issue is with another package, not typescript-eslint itself package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants