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

Enhancement: [switch-exhaustiveness-check] require default cases for non-union types #7862

Closed as not planned
Labels
duplicateThis issue or pull request already existspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@ST-DDT

Description

@ST-DDT

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/switch-exhaustiveness-check/

Description

I propose that theswitch-exhaustiveness-check checksswitch statements that operate on non-union-types and require them to have a default case to ensure they are exhaustive.

Fail

constvalue:number=Math.floor(Math.random()*3);switch(value){case0:console.log("zero");return;case1:console.log("one");return;}

Pass

constvalue:number=Math.floor(Math.random()*3);switch(value){case0:console.log("zero");return;case1:console.log("one");return;default:console.log("higher");return;// Ordefault:// Do nothing}

Additional Info

Since it would break projects that have theswitch-exhaustiveness-check enabled, but don't have all their switch statements fully exhaustive, this should probably locked behind a default false option. Maybe this could be turned on by default with the next major version.

This option can not be replaced withdefault-case due to#7539.

Originally searched for during:

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existspackage: 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