-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do thisRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
TypeScript Version: 4.0.2
Search Terms: nullish coalescing possibly undefined
Code
let x: string | undefined;
let a: string | undefined;
a ??= "x";
a.length;
let b: string | undefined;
b ??= x;
b.length;
let c: string | undefined;
c = c ?? x ?? "x";
c.length;
let d: string | undefined;
d ??= x ?? "x";
d.length;
Expected behavior:
a.length
passes, b.length
fails (b
undefined), c.length
passes, d.length
passes, because it becomes a string
Actual behavior:
d.length
fails because not narrowed to string
.
Related Issues: none found
shian15810, Vendicated, Nokel81, vvnsze and iamswain25
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHelp WantedYou can do thisYou can do thisRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone