π Search Terms
import type auto-import
β
Viability Checklist
β Suggestion
When an import is generated automatically (by the language server?), I'd like to be able to have it generate a type import if the imported symbol is used in the file only as a type. Probably, this preference would have options for whether the type import should be of the import type or the import { type ... } form.
π Motivating Example
See below
π» Use Cases
Some codebases prefer to use type-only imports whenever possible to indicate to readers that an import isn't actually used as a value. Meanwhile, other codebases prefer the brevity of import without type.
Currently, a number of TS compiler settings influence the auto-imports that the language server generates, but some of those settings are hard to turn on in existing codebases (e.g., verbatimModuleSyntax, because of how it effects interop) and others are deprecated. Moreover, none of them are actually designed to apply a stylistic preference across the board βΒ they only lead to type imports being generated when it's absolutely necessary for interop, so they won't generate type-only imports as often as a user of this preference would want.
@andrewbranch made the case for adding preference in #54664
The flags that affect type-only auto imports... affect things in precisely the way that the compiler requires, minus bugs. None of them are specifically designed to control auto-imports. It sounds like an antipattern to use compiler options that are supposed to control real things in order to arrive at an editor behavior that matches a particular stylistic preference, so I would much rather give you a user preference.
Really, this issue is just a duplicate of #54664, because the original author closed that issue for unrelated reasons.
π Search Terms
import type auto-import
β Viability Checklist
β Suggestion
When an import is generated automatically (by the language server?), I'd like to be able to have it generate a
typeimport if the imported symbol is used in the file only as a type. Probably, this preference would have options for whether the type import should be of theimport typeor theimport { type ... }form.π Motivating Example
See below
π» Use Cases
Some codebases prefer to use type-only imports whenever possible to indicate to readers that an import isn't actually used as a value. Meanwhile, other codebases prefer the brevity of
importwithouttype.Currently, a number of TS compiler settings influence the auto-imports that the language server generates, but some of those settings are hard to turn on in existing codebases (e.g.,
verbatimModuleSyntax, because of how it effects interop) and others are deprecated. Moreover, none of them are actually designed to apply a stylistic preference across the board βΒ they only lead totypeimports being generated when it's absolutely necessary for interop, so they won't generate type-only imports as often as a user of this preference would want.@andrewbranch made the case for adding preference in #54664
Really, this issue is just a duplicate of #54664, because the original author closed that issue for unrelated reasons.