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

Loosen @typescript-eslint/switch-exhaustiveness-check rule to allow default case #390

Merged

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Feb 19, 2025

@typescript-eslint/switch-exhaustiveness-check checks if each case of a switch statement is handled. By default in the case of a union type, each union member must be handled explicitly. This change loosens is a bit, to allow default as well, rather than specifying each union member explicitly. For example, the following is now allowed, but previously was not:

type SomeType = 'foo' | 'bar' | 'baz';
declare const someVariable: SomeType;

switch (someVariable) {
  case 'foo':
    // ...

  case: 'bar':
    // ...

  // Implicitly handles `baz`
  default:
    // ...
}

This required bumping typescript-eslint as well, since this option was added in a more recent version.

@Mrtenz Mrtenz marked this pull request as ready for review February 19, 2025 13:13
@Mrtenz Mrtenz requested review from a team as code owners February 19, 2025 13:13
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Mrtenz Mrtenz merged commit 3276a93 into main Feb 19, 2025
22 checks passed
@Mrtenz Mrtenz deleted the mrtenz/loosen-@typescript-eslint/switch-exhaustiveness-check branch February 19, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants