-
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
TS1108 "problem" showing on pure Javascript (node) file - Erroneous Error Flag #48224
Comments
@sandersn Looks like node does allow top level returns so we may want to exclude this from the default JS syntax checks @robertblum-psi This was added in 1.65, see https://code.visualstudio.com/updates/v1_65#_syntax-error-reporting-in-javascript-files for details and how you can disable this |
Javascript and Nodejs are not Typescript, and have their own conception of typing that is often radically different than Typescript's. It is a bad idea to enable this for Javascript by default. This change needs to be reverted. |
@robertblum-psi This is not related to TS vs JS These new checks enabled for JavaScript assumed that top level return statements are always a mistake (because in most JS environments they are). However it looks like node sometimes allows them, so we likely don't want to enable this specific check by default Worth noting that returns are still invalid in node if the file is a module and using them goes against the JS spec afaik |
@mjbvz |
Node always does AFAIK. JS and Nodejs are very flexible. It occurs to me that some thought then ought to be given to a node flavor of Javascript, like there is one for REACT. I am not advocating this. I would much rather that there be no Typescript checks on Javascript code, full stop. |
The checks that have been enabled are not typing related (that’s what const foo = {
foo = 1,
bar = 2,
} now it is. These kinds of checks are a good thing. |
Does the mentioned setting not work for you? |
There seems to be some confusion here. The intent of the functionality is to error on illegal JavaScript constructs. This is implemented by using the TypeScript checker and filtering for those particular things which are also illegal in JS. Exposing the implementation details of how this happens to the user is, of course, intentionally not done. |
Um... It clearly outputs a TS(1108) error. That is a Typescript error. You appear to be using a typescript parser somewhere on JavaScript code. And, because of this one error, I now realize that many (if not all) JS errors VS Code flags are presented with Typescript error messages.
I down-leveled to 1.64.2 to get work done. And...
If this is so, why would I want or need to enable or disable setting? Such things should be seamless. If they are "too complex for the parser", fix the parser. (Or maybe, do nothing.) Philosophically, I have no problem with fixing the very very very rare occurrence of something that fails the syntax checker when I run my program. I occasionally had to do that even when I used Eclipse. Good programmers test before shipping, so where is the need for this feature? Your solution feels error prone (proven) and like a solution searching for a problem (or a very low priority one). Perfect is the enemy of good. What I had before was good. No, it was very good. Which brings us back to the setting: My 2 cents is, if the setting is new, set it to disabled and advertise the feature. If the setting existed and was set to false in previous releases and is now set to true, set it back to false by default. |
This is correct; the JS intellisense experience (completions, navigation, errors, hover info, outlining, refactoring, etc) is all powered by the TS engine and they do share error codes. This has been the case since VS Code launched. Regarding this feature, user feedback was broadly consistent that people didn't like not seeing error squiggles on syntax errors, since it's generally easier to just fix these things in the editor than wait for the script to fail to load. We launched this feature with a very constrained set of errors that we thought would 100% of the time be runtime syntax errors, but overlooked this case. VS Code has evolved to have many new highly-requested features over the years. This one, as you can see, shipped with a bug, which we'll fix shortly. New features may appear again in the future based on user feedback; if this isn't compatible with your workflow/worldview, I would recommend disabling updates entirely. |
I think we may be misunderstanding each other. I believe I became mislead by the advice on javascript.validate.enable chicken switch. It appears to be on in 1.64.2! At least, it is on now when I looked in settings, so it must be a feature I was otherwise okay with. I never manually enabled it, so it must have been enabled from inception. If this is the case, you are already fixing my bug, namely the return statement being erroneously flagged as invalid. Thank you. If javascript.validate.enable got enabled by installing 1.65.2, then I do have an an additional issue. If javascript.validate.enable was disabled before this update, it should have remained disabled. It is a best practice to advertise a new feature, rather than turning it on without permission. Of course, there are exceptions, like security features, or enhancements that won't surprise the user or impede workflow. Is this one the latter? If it weren't for the return bug.... maybe?
I remember when an update broke GIT. I down-leveled one release and "disabled updates entirely". Ok, I set it to manual. GIT not working in the IDE (when it worked adequately previously) wasn't compatible with my workflow or worldview. I set it to auto the month I found it fixed. |
Maybe it would be nice to have some special form of comment to disable such errors for the specific line. E.g. I have tried on the
|
@MartinJohns Nice, but even the current |
Since we are talking about a tslint function, perhaps a rules property should be surfaced in settings: js-rules? |
Note that function container() {
}
return I must have mistakenly only tested modules for this error. Edit: reinforced by the fact that it was the very last test case of grammar errors, in the final section labelled "other weirdness". |
Turns out it's only an error in modules. It's possible to keep this error on the list of "OK for JS" errors and make the checker code stop issuing it for JS scripts only. However, I don't think the error is valuable enough to do that. Fixes #48224
* No error on toplevel return in JS Turns out it's only an error in modules. It's possible to keep this error on the list of "OK for JS" errors and make the checker code stop issuing it for JS scripts only. However, I don't think the error is valuable enough to do that. Fixes #48224 * Restore 'return' statement. * Update Baselines and/or Applied Lint Fixes * Re-add missing baselines * No error in toplevel script files Only issue "no top-level return" error for modules, not scripts, regardless of whether it's TS or JS. * Keep Disallowing return in ambient locations * Allow toplevel return only in non-ESM JS files * Add test of toplevel return in JS script * Revert "Add test of toplevel return in JS script" This reverts commit 2a6dec4. * Revert "Allow toplevel return only in non-ESM JS files" This reverts commit 6291ae3. * Revert "Keep Disallowing return in ambient locations" This reverts commit 714ea8e. * Revert "No error in toplevel script files" This reverts commit 2056e13. * restore orphaned baseline Co-authored-by: Daniel Rosenwasser <[email protected]> Co-authored-by: TypeScript Bot <[email protected]>
@sandersn I see "fix available". When does that mean it will show up in a VS Code version update? June? Or do I need to download some sort of hot fix? |
|
I just came across this problem. If either |
Issue Type: Bug
PROBLEMS pane shows:
[JS] file.js (1)
A 'return' statement can only be used within a function body. ts(1108) [400,5]
My node Javascript file is statements that call defined functions. These statements have an if statement that executes a return statement when true. The program is Javascript, and recognized as such by editor. There is no typescript in the environment. This bug appeared immediately after VS Code updated to February 2022 version (1.65.2). It did not appear in the previous version with the exact same file. The program runs properly on the target when run.
UPDATE: I have installed 1.64.2 to remediate issue. The problem does not occur down-level.
The program looks like this:
#!/usr/bin/env node
statements and function definitions
if ( x == y)
return
statements
A Typescript error should not show for a Javascript file.
VS Code version: Code 1.65.2 (c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1, 2022-03-10T14:33:55.248Z)
OS version: Windows_NT x64 10.0.19043
Restricted Mode: No
System Info
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Extensions (11)
(17 theme extensions excluded)
A/B Experiments
The text was updated successfully, but these errors were encountered: