-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Feedback on 'import type' UX for editors #36038
Comments
Another case we talked about is whether the This is a slightly different problem than auto import. With auto import the user has indicated they want to use a specific type whereas with On the other hand, adding a normal Would be interested in hearing others thoughts on this case. |
I think for most users it's preferable to always use standard Maybe this could be configurable in a setting, but even for users who need it I think the number of cases where Thinking back on cases where I could use this, it was always either for a Node module or some subset of files that would be split in my build, such as an Angular module or a dynamic React component. I'm not sure we'd want that level of logic (import type if among these files, but not among these other peer files) in config. |
I kind of agree with this, but only because we don't have something that can automatically promote/demote an import; however, the issue with that is that for long import lists, I wouldn't want to think about formatting diffs. At the very least, something reasonable would be to always prefer When
Would a better behavior be to only do this when |
@DanielRosenwasser wouldn't that just cause more problems for the user? I don't know why
|
I’m not sure I understand this statement. Let’s say you have an existing type-only import of something from module import type { FirstImport } from "./a";
import { SecondImport } from "./a"; or with import { FirstImport, SecondImport } from "./a"; because the emit will be exactly the same. With either strategy, accepting the auto-import adds |
I think I agree that auto-import shouldn’t use type-only imports by default, but it’s unclear what to do when considering an auto-import from a module where the user already has a type-only import. I think I would break it down like this (in order of priority):
(This logic is incomplete because it doesn’t address existing namespace imports, which cannot have named imports added to them, but that’s a bit too far in the weeds at the moment.) |
This is a problem, the auto import here should add it to the type only import and get a TS error that they need to resolve manually. The only use case I can come up with for type only imports is when it's imperative that only types are imported for the purpose of typing dynamically imported modules. In my case, allowing this conversion to happen makes it very easy to accidentally re-introduce my component to the bundle and subsequently increase VS Code's start up time by 20-50ms. It doesn't matter if the emit will be exactly the same or not, the resulting error in the above scenario would point out the problem that I made a mistake and I need to rethink what I'm importing. |
This is (sort of accidentally) the way it works today in the beta, and we immediately got independent bug reports about it (one from @DanielRosenwasser): #36002, #36033. I’m not necessarily saying you’re wrong, but clearly it was unexpected right away. People expect quick fixes / auto imports to be valid—it’s jarring when an automated fix introduces a new error. And on the other hand, if we simply don’t offer auto-imports in value positions from type-imported modules, we will definitely get bug reports about that. |
Well you'll get a bug report from me if you convert type imports to non-type imports with an auto import, or add separate import statements for the same file when a type import already exists 😉 Do you have links to why this was added; what are the goals, use cases, etc.? |
The original PR gives a fairly thorough background and links to ~10 motivating issues. #35200 |
Hey, I think it's important to note that the primary use-cases for
There's a use-case that I think keeps being brought up is "I want to avoid creating runtime dependencies", but I don't think that's one of the use-cases we're aiming to serve with this feature. In the cases where you're hyper-conscious of creating runtime API dependencies:
|
How do we plan to handle this before the 3.8 RC? My feeling is that we can probably push out features such as converting |
Can you be more specific on what we want to handle before the RC? As far as I understand, the suggestion diagnostic is gone, right @andrewbranch? Ideally it should just be a quick fix for users who turn on Otherwise, the work to address the gaps are being done on #36092 and should be in the RC itself. |
The suggestion diagnostic is removed in #36092. |
Closing this issue as is seems all of our feedback has been addressed |
I just updated VS Code to build using TypeScript 3.8 nightly. From this, the VS Code team has some feedback on the UX around the new
import type
syntax. I've captured some of our general feedback here. I'll also be opening issues for specific problems I've noticedThe
...
suggestions to convert imports toimport type
feel intrusiveCurrently, TypeScript returns a suggestion for every import that only imports types. These suggestions are rendered as
...
underlines by VS CodeWe feel these suggestions are intrusive. In our understanding,
import type
seems like an advanced feature that is only really required in a few cases. There is nothing strictly wrong with using a normalimport
since TS has always been smart enough not to generate an import in the emitted code.I believe we should disable these suggestions and instead leave them to the linter.
Auto import should not use
import type
Currently, if you are only referencing a value as a type, auto import will try to import it using
import type
. This can get weird if you later try using the same symbol as a concrete value in the same fileAgain, I believe that it would be better to add a standard
import
and let users explicitly change it toimport type
if they desire./cc @Tyriar @connor4312 for VS Code
/cc @minestarks @amcasey for other editor feedback
The text was updated successfully, but these errors were encountered: