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
{{ message }}
Repository navigation
unreachable code diagnostic should be severity suggestion, not error #24026
Thanks to #19392 we can now produce Suggestions with Code Fixes rather than error diagnostics.
This is a good way for TypeScript to report that a program is valid TypeScript, but likely contains a mistake.
Unreachable code is exactly this case. Developers sometimes add a quick throw statement just to make a runtime assertion while debugging. Then they get an error diagnostic which forces them to comment out remaining lines in this control flow, or add a fake guard condititonal if (1==1) throw new Error('')
I think unreachable code is not an invalid TypeScript program and therefore should be treated like an unused variable.
Just to clarify, we would still report an error under --allowUnreachableCode false, and we would still not report any diagnostics under --allowUnreachableCode true. the only change would be --allowUnreachableCode === undefined (i.e. default behavior) it would be a suggestion and not an error.
Since we are at it, we should also add a quick fix to remove the unreachable statements.
We could also look into marking the diagnostic as unused to let VS/VSCode grey out the whole section of unreachable code.
Activity
mhegazy commentedon May 10, 2018
Just to clarify, we would still report an error under
--allowUnreachableCode false, and we would still not report any diagnostics under--allowUnreachableCode true. the only change would be--allowUnreachableCode === undefined(i.e. default behavior) it would be a suggestion and not an error.Since we are at it, we should also add a quick fix to remove the unreachable statements.
We could also look into marking the diagnostic as unused to let VS/VSCode grey out the whole section of unreachable code.
mhegazy commentedon May 10, 2018
Also same applies for
--allowUnusedLabels.