Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

The "never nullish" diagnostic (TS2869/TS2881) was not reported when the left operand of ?? was wrapped in parentheses because checkNullishCoalesceOperandRight checked node.parent directly without traversing through outer expressions.

const x: { y: string | undefined } | undefined = undefined as any;

const foo = x?.y ?? `oops` ?? "";      // Error reported ✓
const bar = (x?.y ?? `oops`) ?? "";    // Error NOT reported (bug)

Changes

  • Remove checkNullishCoalesceOperandRight function and its call
  • Modify getSyntacticNullishnessSemantics to recurse on the right operand for ??, ??=, =, and , operators instead of returning PredicateSemanticsSometimes

This allows semantic analysis to properly evaluate through ?? chains regardless of parenthesization.

Ports microsoft/TypeScript#62789

Original prompt

Port microsoft/TypeScript#62789

Custom agent used: Strada to Corsa Port Expert
A Go and TypeScript expert who can easily figure out how to port PRs from one language to another


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ressions wrapped in parentheses

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Port changes from TypeScript PR 62789 Port TypeScript PR #62789: Fix "never nullish" diagnostic missing expressions wrapped in parentheses Jan 9, 2026
Copilot AI requested a review from RyanCavanaugh January 9, 2026 19:21
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review January 14, 2026 19:48
Copilot AI review requested due to automatic review settings January 14, 2026 19:48
@RyanCavanaugh RyanCavanaugh added this pull request to the merge queue Jan 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR ports TypeScript PR #62789, which fixes a bug where the "never nullish" diagnostic (TS2869/TS2881) was not reported when the left operand of ?? was wrapped in parentheses. The fix removes a separate right operand check function and instead modifies the semantic analysis to properly recurse through nullish coalescing chains.

Changes:

  • Removed checkNullishCoalesceOperandRight function which incorrectly checked parent nodes without traversing outer expressions
  • Modified getSyntacticNullishnessSemantics to recurse on right operands for ??, ??=, =, and , operators
  • Updated test baselines showing improved error reporting with more specific diagnostic codes

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/checker/checker.go Removed checkNullishCoalesceOperandRight function and modified getSyntacticNullishnessSemantics to recurse on right operands for certain operators
testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt Updated baseline showing improved error diagnostics with proper TS2869 codes instead of TS2881
testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt.diff Diff showing baseline changes with better error locations and codes

Merged via the queue into main with commit 05587c0 Jan 14, 2026
28 checks passed
@RyanCavanaugh RyanCavanaugh deleted the copilot/port-typescript-pull-62789 branch January 14, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants