-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Extract-method with namespace declaration results in invalid code #18546
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
I'm curious about why it's doing that but, unless I'm mistaken, that's not even legal code. Generally speaking, I don't think we make many guarantees about the behavior of refactorings and code fixes on non-compiling code. |
If you do it with a class instead (also illegal), you get |
The same thing happens for a nested function, which is legal. I believe the issue is that |
Actually, namespaces are legal to appear anywhere a declaration would be. In that case they create a local variable, not a global variable. |
@Andy-MS, that seems reasonable. Is there a switch or something I have to set to suppress/disable TS1235 (a namespace declaration is only allowed in a namespace or module)? |
That is strange, I was seeing no error yesterday. Probably my services were failing but vscode doesn't tell me. I wonder why we have this restriction, since namespaces are legal inside of a module (not global) and the emit for a namespace inside a function looks fine. |
selection Fixes microsoft#18546 (cherry picked from commit af49c60)
selection Fixes microsoft#18546 (cherry picked from commit af49c60)
TypeScript Version: nightly (2.6.0-dev.20170916)
See test
extract-method-empty-namespace.ts
.Code
Extract "namespace N" out to a global function.
Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: