-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Existing import type
prevents autocompletion of value import for TypeScript
#44804
Comments
import type
prevents autocompletion of value importsimport type
prevents autocompletion of value import for TypeScript
I think the completion entry showing up at all might be a mistake, but the decision to not “promote” imports from type-only to regular imports was very intentional. If you bother to write an import as type-only, we would like to take that as a very strong cue that you don’t want to accidentally add a runtime dependency on the module you’re importing, and so we don’t want to quietly undermine your intention by undoing that type-only annotation as soon as you try to reference those identifiers in a value position. Unfortunately, we don’t actually know what imports were auto-imported and what were written by hand. There seem to be an assumption that we don’t auto-import anything as type-only, but that’s not true under |
Yeah. The assumption makes some sense by default, but what you wrote definitely applies in our case. We use I'd be glad for the "promotion" to happen automatically when that config is enabled. I'd also be happy with some sort of "warning, you're promoting this import from type to value, this might affect your build more than you expect" if regular autocompletion muscle memory still works. In cases where the setting is not enabled, I think the current behaviour is still kind of confusing — autocomplete muscle memory does select something, but that something has no effect. I'm not sure what a good UX in that case would be. |
Well, it has the same effect as any other non-auto-import completion: it completes the identifier so you don’t have to type it yourself 😄 I’m pretty sure what I expected was that type-only-imported identifiers wouldn’t show up in completions in value positions at all. I also have a memory of a codefix being available to do the promotion, so the sequence would be (1) accept completion, (2) see error with lightbulb, (3) perform codefix. But apparently I made that up, as no such codefix exists. That seems like it would be an ok baseline experience, and we could extend the promotion behavior to everyone regardless of settings if there is sufficient demand. |
Anything I could do to help this along? This is still tripping me up, sometimes (literally) hundreds of times a day. |
I plan to get to this in for 4.6 (possibly this week). My thinking on it changed after we added |
…on fix. This is just for now until it ends up in more stable builds. We can revert this if there are any unexpected issues. See microsoft/TypeScript#44804
…on fix. This is just for now until it ends up in more stable builds. We can revert this if there are any unexpected issues. See microsoft/TypeScript#44804
…on fix. This is just for now until it ends up in more stable builds. We can revert this if there are any unexpected issues. See microsoft/TypeScript#44804
Issue Type: Bug
Consider the following code:
Now type:
on a new line inside
a.ts
and try to autocomplete the import ofB
to use it as a constructor.Expected behaviour
VSCode changes the import of
B
from a type import to a value import.(It would be a syntax error to add the value import while keeping the type import, so the type import of
B
has to be removed at the same time. In this particular example, I would expect the entireimport type
line to be removed and the import ofB
added to the same line asmakeB
.)Observed behaviour:
VSCode offers an autocompletion dropdown, but the default choice does nothing. There is no choice that will result in a value import of B unless the existing type import is deleted.
Screencap:
Screen.Recording.2021-06-29.at.01.47.40.mov
This is a frustrating experience: If I "happen" to autocomplete something as a value in a given file before I complete it as a type the first time, then autocomplete works naturally and the code is fine. But if I autocomplete something as a type the first time, then VSCode is unable to autocomplete the value import. Even though I know the issue and can work around it every time, autocomplete feels subjectively unreliable.
This kind of situation can be common in a large codebase with
importsNotUsedAsValues
. In particular, I'm working on a project where it is common to use a particular class (Alg
fromcubing/alg
) as a the type of a variable in a given file, only to need the constructor later on.VS Code version: Code 1.57.1 (507ce72a4466fbb27b715c3722558bb15afa9f48, 2021-06-17T13:28:32.912Z)
OS version: Darwin x64 20.5.0
Restricted Mode: No
System Info
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
A/B Experiments
The text was updated successfully, but these errors were encountered: