Skip to content

Conversation

nmhen
Copy link

@nmhen nmhen commented Sep 21, 2025

Fix incorrect type inference where destructured parameters with default values were still considered to include undefined in their type union.

Fixes #7525

Summary

The useExhaustiveSwitchCases rule was incorrectly flagging switch statements as non-exhaustive when using destructured parameters with default values.

Problem: When a parameter has a default value like { b = "thing" }: { b?: "thing" | "other" | "more" }, the
variable b can never be undefined because it has a default value. However, the rule was still requiring an
undefined case in switch statements.

Solution: Added logic to detect when a discriminant variable comes from a destructured parameter with a default
value, and exclude undefined from exhaustiveness checking in those cases.

Test Plan

  • Added new test case invalidIssue7525.ts with scenario of destructured parameters with defaults
    • All existing tests continue to pass
    • The new test verifies that switch statements with destructured params + defaults no longer incorrectly require
      undefined cases

Docs

No documentation changes needed - this is a bug fix that improves existing rule behavior.

…t parameters

Fix incorrect type inference where destructured parameters with default values
were still considered to include undefined in their type union.

Fixes biomejs#7525
Copy link

changeset-bot bot commented Sep 21, 2025

🦋 Changeset detected

Latest commit: 42d8ed3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Sep 21, 2025
Copy link

codspeed-hq bot commented Sep 21, 2025

CodSpeed Performance Report

Merging #7545 will not alter performance

Comparing nmhen:fix-exhaustive-switch-default-params (42d8ed3) with main (8a4f4fc)

Summary

✅ 133 untouched

Copy link
Member

@siketyan siketyan left a comment

Choose a reason for hiding this comment

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

The useExhaustiveSwitchCases uses our type inference, and the issue is not coming from the rule itself, but from the type inference. Fixing the issue within the rule is more like symptomatic therapy, and the issue still exists when the type inference is used in other rules. Implmenting the type narrowing in our type inference will help not only this rule but also other type-powered rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 lint/nursery/useExhaustiveSwitchCases doesn't recognize method params with default values

2 participants