Rule suggestion: Prefer "import type" #1786
Labels
awaiting response
Issues waiting for a reply from the OP or another party
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Mostly separating this out from #1436 so it can have a dedicated issue.
TypeScript 3.8 adds an
import type
syntax which allows you to import type definitions only, for ease of transpilation via tools which don't have type checking like babel. For transpilers, these definitions are ignored and removed on transpilation.The newer compiler also has an
importsNotUsedAsValues
compiler option to clarify whether you want to enforce the use ofimport type
syntax, with the three options:remove
: Don't transpileimport type
definitions, not loading any stateful changes (default)preserve
: Transpileimport type
definitions, loading any stateful changeserror
: Error when plainimport
s are for types only, requiring a separation of stateful/value imports and type importsThat latter option looks like a good candidate for a rule in typescript-eslint. Although the compiler will warn on these errors, an eslint rule can also have an applicable fix as well. This is also not a possible rule for
eslint-plugin-import
, as it requires type checking.This rule, when enabled, will match the behaviour of the
error
variant of theimportsNotUsedAsValues
flag, providing an applicable fix.Example code:
Suggested fix:
The text was updated successfully, but these errors were encountered: