-
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
warning 6133 when namespace declaration follows import #33317
Comments
You're not exporting the namespace. If you aren't, then it makes sense you're getting the error message |
I'm using the namespace solely for separation of, well, namespaces. It's not about building a module. So I don't think exporting it would make sense. |
Are you referencing |
No, it shouldn't be necessary to address anything inside the namespace explicitely with the full identifier including the namespace. I don't have exported members inside the namespace also, and it wouldn't change the behaviour. At this point of time I can either add
to suppress the behaviour, both of which are not very elegant. |
The Your file itself acts as its own namespace... unexported variables inside the file should not leak into other files. Given the following, namespace Test {
export const myVar = 32;
} The following JS is emitted, "use strict";
var Test;
(function (Test) {
Test.myVar = 32;
})(Test || (Test = {})); As you can see, during run-time, a It creates an identifier in both the It is a fact that you're not using the variable You shouldn't use |
Like @AnyhowStep said, if you're using ES modules (which you are since your example has |
@JirkaDellOro It’s fairly likely the error is alerting you to a larger issue: because you’ve added |
Can this statement be found in the official documentation or is it an official guideline? The namespace in this case is necessary not for separating things at runtime, but at designtime. I think @fatcerberus second answer comes closer to addressing the problem
As a developer, I should be telling TS if the file is supposed to become a module or not, and don't expect TS to see the file as such because imports are used. So this behaviour appears faulty. |
|
I'm just going to selectively quote but you should read the whole discussion.
|
To be clear: ESM, at runtime, is a separate execution model compared to execution of regular scripts, and |
@AnyhowStep: Thanks for pointing me there. In the discussion, the person you cite also stated this:
That is one of the reasons I use it, it's not about building a module. I'd use
Would you mind to point me to that specification? I can't find it stated like this in the official specs. Also the compiled code (using ts-ignore) actually works fine and as expected, it's just that the compiler warning doesn't seem to fit or is needless. PS: it's a warning, not an error that would stop compilation. I changed the title of this issue to reflect that. |
Could someone from the TypeScript-Team please comment on this? |
It's the intended behavior |
@RyanCavanaugh: Thanks for tuning in. So I understand the intended behaviour must be to print a warning that the namespace is not read, when its contents accesses imported modules. I can't grasp the idea behind that intension, though. Why does using imports change the meaning or behaviour of the namespace? There is no warning without imports and the compiled code works as intended also with the imports. I'd love to have an explanation I can tell my students so that they know why they have to use |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@fatcerberus : Do you know where I can look that up? |
The pain due to ESM being a separate execution model from normal scripts is why we ended up with But here's what the ECMAScript spec has to say anyway: Notice that only the Module grammar allows See also: "Global code" doesn't allow If that
The |
@fatcerberus Thank you very much for your efforts, that gives me some hints to come up with an explanation for my students. I had to decide which workaround to recommend
I go with export now and stick to "by definition", though it still should work and works to use a module in global code without exporting. At least, export does no harm... |
tsconfig.json: "noUnusedLocals": true,
tsc-version: Version 3.6.2
Result: Warning 6133 'Test' is declared but its value is never read.
Expected: No Warning
The text was updated successfully, but these errors were encountered: