-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [switch-exhaustiveness-check] invalid fix for union with infinite types #6682
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
Comments
Found another related instance: declare const a: number | string;
switch (a) {
case 2: break;
} This should not report anything |
Another interesting case: declare const a: "a" | (string & {});
switch (a) {
case "a": break;
} This has a suggestion but suggestion produces an empty line |
@bradzacher For the |
Report if the literal cases are missing with no default, no auto or suggestion fixer provided. Considering we ignore the |
That's reasonable. So we filter out all infinite types from the union, and require the remaining literals to be exhaustively matched. |
Because TS's boolean type is secretly just an alias for |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play#ts=5.0.1-rc&sourceType=module&code=CYUwxgNghgTiAEYD2A7AzgF3lAXPARFPvAD4EBGxZKArgLbkgwDcAUK2gO4CWGYAFvAAUUAJTwA3q3iIoaBIXx5ycKAGs2MsHIWVlqjawC+rIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6ZAd0vzIAt6AHrwCGsZPkoA3RExTJafRGQDW6KImjQA9tEjgwAXxAGgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA
Repro Code
ESLint Config
tsconfig
Expected Result
No error, no suggestion fixer, or suggestion to add a default case
Actual Result
Fixer produces
case number:
, which is invalid syntax.Additional Info
I'm not sure what the best fix for this issue is, so I hope to get more discussion first.
The text was updated successfully, but these errors were encountered: