Skip to content

Unexpected exhaustive check result for switch statement #29559

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
lriuui0x0 opened this issue Jan 24, 2019 · 1 comment
Closed

Unexpected exhaustive check result for switch statement #29559

lriuui0x0 opened this issue Jan 24, 2019 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@lriuui0x0
Copy link

lriuui0x0 commented Jan 24, 2019

TypeScript Version: [email protected]

Search Terms: switch

Code

const assertUnreachable = (x: never): void => {}

const f = (x: 'a' | 'b') => {
  switch (x) {
    case 'a':
      {
      }
      break;

    case 'a':
      {
      }
      break;
  }
};

const g = (x: { t1: 'a'; t2: 'a1' | 'a2' } | { t1: 'b'; t2: 'b1' | 'b2' }) => {
  switch (x.t1) {
    case 'a':
      {
        switch (x.t2) {
          case 'a1':
            {
            }
            break;

          case 'a2':
            {
            }
            break;

          default: {
            assertUnreachable(x.t2);
          }
        }
      }
      break;
  }
};

Expected behavior:

Function f should not pass the typecheck at the second case block.
Function g should pass the typecheck at assertUnreachable.

Actual behavior:

Function f passes the typecheck at the second case block.
Function g doesn't pass the typecheck at assertUnreachable.

Note that if we put assertUnreachable in function f, it will work. So this seems to be only happening for the nested switch.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 24, 2019
@ahejlsberg
Copy link
Member

This has been fixed by #29563.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants