Skip to content

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

Closed

Description

@alexeagle

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.

Activity

  1. mhegazy commented on May 10, 2018

    @mhegazy
    Contributor

    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.

  2. mhegazy commented on May 10, 2018

    @mhegazy
    Contributor

    Also same applies for --allowUnusedLabels.

  3. ghost added
    FixedA PR has been merged for this issue
    on May 18, 2018
  4. ghost closed this as completedin #24261on May 22, 2018
  5. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions