Skip to content

fix(lint/prefer-optional-chain): resolve trailing comparison values to their constraints - #1154

Merged
camc314 merged 1 commit into
fix/lint-prefer-optional-chain-1393from
fix/lint-prefer-optional-chain-1395
Nov 30, 2026
Merged

camc314 merged 1 commit into
fix/lint-prefer-optional-chain-1393from
fix/lint-prefer-optional-chain-1395

Conversation

@camc314

@camc314 camc314 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Ports oxc-project/tsgolint#1395 (fe037332), including its baseline update.

The unsafe trailing-comparison check read the comparison value's declared type, so a generic value such as T or T[K] wasn't treated as possibly undefined, and the chain was rewritten even though that changes the result:

declare const foo: { bar?: number } | undefined;
function f<T>(v: T) {
  return foo && foo.bar === v; // was fixed to foo?.bar === v
}
// foo = undefined, v = undefined: the original returns undefined, the fix returns true

As in typescript-eslint's isValidAndLastChainOperand, the value is now resolved to its constraint, and instantiable types (type parameters, indexed access and conditional types) count as possibly undefined. !== and != require the value itself to be undefined or null, not void.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: βœ… Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
πŸ“ Code Review βœ… Completed 2026-11-30T11:56:49.807037Z 71a36b9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with πŸ‘€ while any review is running, comments if it has suggestions, and reacts with πŸ‘ once all reviews finish with no findings.

@camc314
camc314 added this pull request to stack #1163 November 30, 2026 11:56
@camc314
camc314 enabled stacked auto-merge November 30, 2026 12:00
@camc314
camc314 added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit f42114c Nov 30, 2026
18 checks passed
@camc314
camc314 deleted the fix/lint-prefer-optional-chain-1395 branch November 30, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants