-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
Bug Report
π Search Terms
Control-flow analysis logical
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
Playground link with relevant code
π» Code
declare function fail(): never;
declare const a: string | null;
declare const b: string | null;
if (!a) fail();
a.charAt(0); // a is correctly narrowed to `string`
b || fail();
b.charAt(0); // Object is possibly 'null'. ts(2531)
π Actual behavior
It seems that the branches of logical expressions do not impact control flow analysis, and thus the logical expression form is not equivalent to the conditional form, resulting in the type of b
not being narrowed.
π Expected behavior
b
narrowed to the string
type.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed