Skip to content
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

Elusive breakage of Add all missing imports source action. Needs further investigation. #134

Open
ericchase opened this issue Oct 22, 2024 · 13 comments

Comments

@ericchase
Copy link

ericchase commented Oct 22, 2024

The JavaScript and TypeScript Nightly v5.7.20240911 update broke some part of the Add all missing imports source action. Ever since then, some imports would be incorrectly imported with the type only attribute; i.e.

import type {} from "";

instead of

import {} from "";

for situations where type only imports are not correct.

@ericchase
Copy link
Author

ericchase commented Oct 22, 2024

JavaScript and TypeScript Nightly v5.7.20240904 works as expected, as far as I can tell.

@mjbvz
Copy link
Contributor

mjbvz commented Oct 22, 2024

What about the current release, v5.7.20241021?

@ericchase
Copy link
Author

ericchase commented Oct 23, 2024

did someone literally just fix this the same day? that's insane unlikely

@ericchase
Copy link
Author

ericchase commented Oct 23, 2024

hmm, i made the mistake of not cloning the current state of my project in which this issue occurred, and now i can't reproduce it. well, next time i run into the problem again (this is NOT a single instance. it has happened to me in other projects), i will try to remember to freeze it

@ericchase ericchase changed the title JavaScript and TypeScript Nightly v5.7.20240911 Breaks Add all missing imports Source Action Elusive breakage of Add all missing imports source action. Needs further investigation. Oct 23, 2024
@ericchase
Copy link
Author

looking back, i didn't perform as thorough an investigation as i should have. if i run into the same behavior again, i'll try to remember to push a repro and test it on a clean os installation.

i'll close this for now as not reproducible

@ericchase ericchase closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@ericchase
Copy link
Author

yay, the problem is happening again, i'll freeze this project and try to create a minimal reproduction. stay tuned

@ericchase ericchase reopened this Oct 24, 2024
@ericchase
Copy link
Author

A demonstration of how the Add all missing imports source action is broken, but normal Add import from ... works as expected.
Image

2024-10-24_09.42.43.mp4

@ericchase
Copy link
Author

here is the most minimal reproduction i could make with actual code that i use:

for anyone who is familiar with Windows Sandbox, here is my fresh installation demonstrating the bug with completely fresh everything:

as promised, v5.7.20240904 works as expected:
Image

any version after that does not work as expected:
Image

@ericchase
Copy link
Author

just in case:
Image

it's hard to explain to non-windows users what Windows Sandbox is and how it's almost literally a "brand-new installation of Windows"[1], so there are no user settings or configurations whatsoever. this is a brand-new installation of vscode with no settings or configurations whatsoever.

[1] https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/windows-sandbox-overview

@ericchase
Copy link
Author

oh right, i almost forgot the most important part:

tsconfig.json

{
  "compilerOptions": {
    "verbatimModuleSyntax": true
  }
}

this bug only happens when this property is enabled

@ericchase
Copy link
Author

this problem is still occurring, and due to the change with typed arrays being generic over array buffer like, we can't really use the older versions of this extension anymore.

if anyone who reads this might have an idea of why this problem now exists, i would appreciate the insight

@ericchase
Copy link
Author

ericchase commented Jan 18, 2025

finding it really hard to believe that no one else has reported this bug yet over the three months that it has been live.

is there a way to simply disable typescript extension from ever writing "import type {}..." statements and only write "import {}..." instead?
it's rather annoying, and i'd rather deal with the unused imports than have to fix the extension's mistake every single time.

@ericchase
Copy link
Author

ericchase commented Jan 18, 2025

microsoft/TypeScript#36038
Seems like a similar topic was being discussed here back in 2020.

microsoft/TypeScript#36412 (comment)

An auto import will only be written as a type-only import if not doing so would result in an error. For that to be true, your tsconfig must have importsNotUsedAsValues: "error", and the place where you’re performing the auto-import must be a type position.

https://www.typescriptlang.org/tsconfig/#importsNotUsedAsValues

Deprecated in favor of verbatimModuleSyntax.

https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax
I'm honestly not sure what this option is supposed to be doing, and I personally feel like the docs suck at explaining it. I'm not sure if I should have it enabled or disabled, but since the problem occurs while it is enabled, I'll disable it and see how things go for a while.

Do note that this problem did not occur with earlier versions of this extension, so there's definitely some iffy stuff going on behind the scenes, but maybe that's exactly how the authors want it to work. Since no one else is talking about this, maybe no one is actually using verbatimModuleSyntax? (There's 4,686,749 downloads of this extension, so it's hard to imagine that being the case.)

Would still love more information about this topic if anyone who comes across this issue has any!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants