-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Configuration For Treating JS/TS Files as Independent Units (modules) #14279
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
What do you mean single units? if these are modules, wold not they have at least one import or export? if they are not, why should they be "units"? |
@mhegazy The request would be to treat all JavaScript files as modules by default, even if they do not follow the standard module conventions. We've seen this type of issue few reported a few times, specifically when people are working on websites. Even though the JavaScript files may be be loaded on separate pages, as far as I know, there is no way to configure VScode to treat these files as independent modules, at least without making the files proper modules. |
@mhegazy Mainly this is annoying for when you're going to write a module eventually, but TypeScript keeps bugging you. @mjbvz, while I agree that this is annoying, how do you plan to surface it in VS Code? Do you believe there are no people writing global-style code in VSC? Is it possible that a different group of people would report the opposite issue? |
@DanielRosenwasser I would see this being something that users can opt into by enabling another compiler option in the See microsoft/vscode#22011 for another manifestation of this issue. Users either need a way to opt into isolated files in a JS project, or we need to improve TypeScript's handling of multiple definitions of a symbol across multiple JS files |
Is there any documentation on how to persuade TypeScript that a file is in fact a module? I have a file in a Node.js project where TS gives me these errors, despite the file having both imports and exports. Edit: Nevermind, it was a strange issue in PhpStorm that was producing spurious errors from a file that turned out to be fine once PhpStorm was restarted. |
I like the idea with the config, but why only JavaScript files are mentioned here? What about TypeScript files? |
Is there any progress to this issue? It has the label Awaiting More Feedback, but I don't see any open questions? In my opinion the best way to surface this is to provide another compiler option like @mjbvz already suggested. |
Hitting this with two files that run in separate processes. I cant re-use names between the two, but they aren't technically modules. |
I'm the author of the vscode issue @mjbvz refers to. I'd like to also request this feature - we have multiple JS files that run in the same application, use the same APIs, but are independent. I want a jsconfig.json to set options, but I do NOT want the files treated together, but independently. |
Hitting this as well, now I can't even use I'm working in an environment what has custom module resolution and I can't flag my files as independent units anymore. |
"Custom module"? Pah, I don't even have modules. A set of independent
files is all I have. Which is why this would be so useful
…On Fri, 9 Oct 2020 at 20:09, Attila Greguss ***@***.***> wrote:
Hitting this as well, now I can't even use export {}; as a workaround
after an update because it gets included with es6 module resolution.
I'm working in an environment what has custom module resolution and I
can't flag my files as independent units anymore.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14279 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADZSIPQWZQKAVHSF4CNQ3DSJ5NVXANCNFSM4DBK537A>
.
|
I also faced with such need ... currently TypeScript enforce developer to add |
I also have this problem, I'm creating a project which has a series of typescript files, each of which represents a "userscript" (greasemonkey / tampermonkey script), so each file is totally independent, and also, is not a module. The fact that I want to have these files all within one vscode project means I can't use the same variable names in any of them. |
Here yet another use-case in which this problem occurs: We have built a data-processing platform based on the Graal runtime (runs Javascript, C, Java, Python, ... in the same memory space) and author data-processing scripts in Typescript. Namespacing is, of course, an option but seems unnecessarily pedantic if any one script is only ever run by itself (what other posts call "in isolation", i.e., as the only script within in the scope of the runtime). As a work-around, a trip down Memory Lane might do the trick: Have your build tool enclose the script in an anonymous function that is executed immediately. In Grunt, for example, using
In
|
Just got bitten by this AGAIN, where a function with the same name (and same functionality, as it happens) was defined in two files, one with a JSDoc for the parameters, one without (and so got typed as taking "any" parameter types). An erroneous call to the function was written and not caught because VSCode found the "any" overload. |
Can you explain how #47495 fixes this issue? I can't see it right now but I may be being dense. What do I set to have each JS file (just JS, no modules in sight at all) considered in isolation? |
|
How do I understand when / in which version this will happen? In the latest vscode, and in the typescript online doc, there doesn't seem to be support for "moduleDetection: force" still. |
Looks like Typescript 4.7 will introduce it that's the merge I saw. That version is in beta. |
Is there any workaround? iirc having I guess the only other option would be to downgrade TSC to 3.9? We didn't have this bug then. |
@ValeTheVioletMote I'm not sure what issues you might be having since the comment is sparse on details. If you're having an issue in a latest version of TS, it might be worth filing an issue with more detail; if not, a StackOverflow question might be a better direction. |
Typescript 4.7 appears to have been released now with the Beyond that I don't think there's any other way. |
You can read up on the the New issues should be filed separately. |
From microsoft/vscode#16892
TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
For a JavaScript project
jsconfig.json
a.js
b.js
Expected behavior:
There should be a way to configure TypeScript to treat
a.js
andb.js
as isolated units. That way,foo
would have the type as defined in its fileActual behavior:
The files are treated as a single unit.
foo
either has astring
ornumber
type in both files.The text was updated successfully, but these errors were encountered: