-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [switch-exhaustiveness-check] fix new allowDefaultCaseForExhaustiveSwitch option #8176
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
Conversation
Thanks for the PR, @Zamiell! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I was just hit by the issue when enabling this new option that looks good! |
@ArnaudBarre You are right, I will add the following "allow" test to address this: // switch with default clause on primitive +
// "allowDefaultCaseForExhaustiveSwitch" option
{
code: `
declare const value: number | string;
switch (value) {
case 0:
return 0;
case 1:
return 1;
default:
return -1;
}
`,
options: [
{
allowDefaultCaseForExhaustiveSwitch: false,
requireDefaultForNonUnion: false,
},
],
}, |
In order to address this, I added a new prop to the metadata called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
PR Checklist
Overview
At first I thought this was a trivial fix to just check for
isUnion
, but then someone pointed out that it would fail forstring | number
, which is a union, but should actually have a default case.Thus, I revert to creating a
doesTypeContainNonLiteralType
function.