-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
π Search Terms
comma operator nullish coalescing never
π Version & Regression Information
- This changed between versions 5.5.4 and 5.6.3
β― Playground Link
π» Code
declare const maybe: true | null;
let i = 0;
// This works
const a = maybe ?? true;
// This works
const b = (i++, maybe);
const c = b ?? true;
// This fails
const d = (i++, maybe) ?? true;π Actual behavior
A build error occurs:
Right operand of ?? is unreachable because the left operand is never nullish. ts(2869)
π Expected behavior
The code should compile without error; The left side of the ?? can still be nullish in the const d case.
The const b / const c case is functionally identical and is recognized to be valid
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript