Skip to content

unreachable code diagnostic should be severity suggestion, not error #24026

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

Closed
alexeagle opened this issue May 10, 2018 · 2 comments
Closed

unreachable code diagnostic should be severity suggestion, not error #24026

alexeagle opened this issue May 10, 2018 · 2 comments
Labels
Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@alexeagle
Copy link
Contributor

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.

@mhegazy
Copy link
Contributor

mhegazy commented 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 mhegazy added the Suggestion An idea for TypeScript label May 10, 2018
@mhegazy mhegazy added this to the TypeScript 3.0 milestone May 10, 2018
@mhegazy mhegazy assigned ghost May 10, 2018
@mhegazy mhegazy added the Domain: Error Messages The issue relates to error messaging label May 10, 2018
@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2018

Also same applies for --allowUnusedLabels.

@ghost ghost added the Fixed A PR has been merged for this issue label May 18, 2018
@ghost ghost closed this as completed in #24261 May 22, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants