-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unwanted auto-imports in script files #55256
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
Comments
The title seems backwards; do you mean "with |
"module": "none"
"module": "none"
If this is still not resolved or assigned to anyone, may i have a go ? |
@hardikkoul Just go for it: Hmm, after rereading the link: This issue do not have a "help wanted" or "Backlog" tag... |
@hardikkoul fine by me 👍 There’s a function |
@HolgerJeromin , @andrewbranch thanks , will start analyzing. |
I can see there is a method programContainsModules , so its already checking for module config , but the catch is it only executes when none of the other conditions of shouldOfferImportCompletions return true. Correct me if my understanding is wrong. |
You can just add a check that |
Let me know if it needs any revisions or is totally wrong (which is a possibility :P) , i opted not to touch the existing method just in case something breaks. |
Sorry for the mess up while resolving conflicts @andrewbranch , i have closed and deleted the previous PR and branch , have created a new branch and raised a PR without conflicts, please review |
Moving the discussion from the merged PR to this issue. Please reopen because the PR does not change behaviour. ref #55556 (comment)
Yes. My code is something like this non-module file with namespaces and a 3.7 MByte outfile: namespace TcHmi.Config {
export function get() {
return TcHmi.System.config; // <-- Defined in some other file
}
} I will get this code: import { parse } from "acorn";
namespace TcHmi.Config {
export function get() {
parse
return TcHmi.System.config; // <-- Defined in some other file
}
} Typescript handles this code as a module and correctly has not idea what I have declare namespace acorn { // I access this namespace
/*...*/
function parse(input: string, options?: Options): ESTree.Program;
}
declare module "acorn" {
export = acorn
} |
Ok, I see. The import is allowed, but turning your file into a module causes other errors. But that may be the case in any We could possibly consider preventing auto-imports when there is a top-level namespace declaration in a script that already merges with one in another file. |
@andrewbranch |
"module": "none"
Accepting PRs for this:
|
Found #35395 Moving |
Bug Report
I have a mixture of module and non-module code.
The problem occurs when I edit non-module files (tsconfig:
"module": "none"
).Sometimes when using auto-completion (in VisualStudio 2022) typescript finds a "matching" name from the module world and adds a line like
into the first line of my file.
But as the current file was configured as
"module": "none"
thisimport
pushes typescript into modules mode and the current code is invalid.🔎 Search Terms
intellisense
auto-import
modules
🕗 Version & Regression Information
This bug is many years old and persists in Typescript 5.1.
The text was updated successfully, but these errors were encountered: