mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
da487ee641
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: RyanCavanaugh <[email protected]>
23 lines
1017 B
Plaintext
23 lines
1017 B
Plaintext
//// [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;
|
|
>a : Symbol(a, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 3, 11))
|
|
>b : Symbol(b, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 3, 23))
|
|
|
|
const p = (a ? b ?? null : null) ?? 0;
|
|
>p : Symbol(p, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 4, 5))
|
|
>a : Symbol(a, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 3, 11))
|
|
>b : Symbol(b, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 3, 23))
|
|
|
|
declare let x: string | null | undefined;
|
|
>x : Symbol(x, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 6, 11))
|
|
|
|
const q = (x ??= null) ?? 0;
|
|
>q : Symbol(q, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 7, 5))
|
|
>x : Symbol(x, Decl(nullishCoalescingAlwaysNullFalsePositive.ts, 6, 11))
|
|
|