Files
tsgo/testdata/baselines/reference/compiler/nullishCoalescingAlwaysNullFalsePositive.js
da487ee641 Fix TS2871 false positive for ?? operator in nullish coalescing check (#4586)
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: RyanCavanaugh <[email protected]>
2026-07-17 16:06:42 +00:00

20 lines
687 B
TypeScript

//// [tests/cases/compiler/nullishCoalescingAlwaysNullFalsePositive.ts] ////
//// [nullishCoalescingAlwaysNullFalsePositive.ts]
// Repro for https://github.com/microsoft/TypeScript/issues/63642
// TS2871 false positive: conditional with ?? null in true branch
declare let a: unknown, b: unknown;
const p = (a ? b ?? null : null) ?? 0;
declare let x: string | null | undefined;
const q = (x ??= null) ?? 0;
//// [nullishCoalescingAlwaysNullFalsePositive.js]
"use strict";
// Repro for https://github.com/microsoft/TypeScript/issues/63642
// TS2871 false positive: conditional with ?? null in true branch
const p = (a ? b ?? null : null) ?? 0;
const q = (x ??= null) ?? 0;