Skip to content
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

Switch on interface with single case not considered exhaustive #18851

Closed
mpal9000 opened this issue Sep 29, 2017 · 2 comments
Closed

Switch on interface with single case not considered exhaustive #18851

mpal9000 opened this issue Sep 29, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@mpal9000
Copy link

TypeScript Version: 2.5.2

Code

interface Action {
  readonly type: 'Action1',
}

export const assertNever = (action:never):never => {
  throw new Error('Unhandled action')
}

const fn = (action: Action) => {
  switch (action.type) {
    case 'Action1': {
      return 'action1'
    }

    default: {
      return assertNever(action) // incorrect error
    }
  }
}

Expected behavior:
action inside default block should have type never

Actual behavior:
action inside default block has type Action

Similar fixed issue: #12771

Playground: https://goo.gl/rs6TgW

@DanielRosenwasser
Copy link
Member

Hey @mpal9000, this looks to me like a potential duplicate of #18056

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Sep 30, 2017
@mpal9000
Copy link
Author

Hi, you can close this one if you want. Checking action.type in assertNever() is not a solution, because it doesn't work for unions. A built in exhaustiveness checking in switch and future match, without manual assertions, would be an awesome feature in my opinion.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants