You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a TS file, have a syntax error that TypeScript thinks results in unreachable code (see screenshot)
Save a TS file
Watch as valid code is removed, causing a lot of confusion about why everything breaks suddenly
Does this issue occur when all extensions are disabled?: Yes
This has been happening a lot lately but as far as I can remember it's never happened before. We had recently upgraded TypeScript from 3.7.2 to 4.0.3, but as far as I can tell with investigation nothing else about our app configuration or VSCode common settings have changed.
I disabled all extensions, ran all of the linters separately, etc, and my code keeps being removed when I accidentally save with syntax errors.
The TypeScript compiler reports the syntax issues but does not report a 7027 error, the unreachable code error only appears in VS Code.
This does not happen when allowUnreachableCode is true, but we don't want to allow unreachable code.
Example:
If I save this file, the underscore code will be removed.
The text was updated successfully, but these errors were encountered:
Sure. I didn't type it out because that code doesn't matter, it's any unreachable code. I can see how that wasn't clear. Here's a minimally reproducible file. Copy/paste, then save, and the console.log line will disappear.
This is not the default behavior. It looks like you've configured code actions on save, which means this is the expected behavior
We generally can't know that the code is unreachable because of an expected syntax error vs being truly unreachable (and we also can't assume that code will always be syntax error free and just disable unreachable code checking)
For what it's worth, I also found this behavior to be quite surprising and it took a few instances for me to be sure I wasn't accidentally deleting code myself since the deletion can occur far away from the syntax error where a change has been made.
I didn't even realize TS had fixes to run so I was using source.fixAll on save thinking eslint was the only provider. Changing that to source.fixAll.eslint works for me, but I figured I should share my experience.
As a point of comparison, it's worth mentioning that eslint's no-unreachable does not have an auto-fix and that's on top of eslint bailing out when there's a syntax error.
Steps to Reproduce:
allowUnreachableCode: false
in tsconfigDoes this issue occur when all extensions are disabled?: Yes
This has been happening a lot lately but as far as I can remember it's never happened before. We had recently upgraded TypeScript from 3.7.2 to 4.0.3, but as far as I can tell with investigation nothing else about our app configuration or VSCode common settings have changed.
I disabled all extensions, ran all of the linters separately, etc, and my code keeps being removed when I accidentally save with syntax errors.
The TypeScript compiler reports the syntax issues but does not report a
7027
error, the unreachable code error only appears in VS Code.This does not happen when
allowUnreachableCode
istrue
, but we don't want to allow unreachable code.Example:
If I save this file, the
underscore
code will be removed.The text was updated successfully, but these errors were encountered: