Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[switch-exhaustiveness-check] Require default case if discriminant type is not a union #2959

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@raymondwang

Description

@raymondwang
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

{"rules": {"@typescript-eslint/switch-exhaustiveness-check":"warn"  }}
typeDay=string;// or numberconstday='Monday'asDay;letresult=0;switch(day){case'Monday':{result=1;break;}}

or

typeDay=any;// or unknown, or a JS variable outside of a TS contextconstday='Monday'asDay;letresult=0;switch(day){case'Monday':{result=1;break;}}

Expected Result

I would expect to see an error message compatible with thedefault-case ESLint rule, indicating that the switch-exhaustiveness-check rule is invalidated because the expression is not a union type.

Actual Result

No error message.

Additional Info

Essentially, I think the best of both worlds is to just have the predictable functionality of thedefault-case rule operate normally except in the event that a switch statement's expression is a union type. Today, there doesn't seem to be any way for the two rules to operate in tandem. Adding this functionality might be a breaking change, but I'm honestly a bit curious how controversial it would be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp