You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeLeft='left';typeRight='right'&{right: 'right'};typeEither=Left|Right;functionassertNever(v: never): never{thrownewError('never');}declareconstvalue: Either;if(value==='left'){constfoo: 'left'=value;}elseif(value==='right'){constbar: 'right'=value;// correctly narrowed despite branding...}else{assertNever(value);// ...but not eliminated as a candidate}
Output
"use strict";functionassertNever(v){thrownewError('never');}if(value==='left'){constfoo=value;}elseif(value==='right'){constbar=value;// correctly narrowed despite branding...}else{assertNever(value);// ...but not eliminated as a candidate}
Bug Report
π Search Terms
assert never branded string literal union type narrowing
π Version & Regression Information
This changed between versions 4.8.4 and 4.9.2-rc
β― Playground Link
Playground link
π» Code
Output
Compiler Options
π Actual behavior
The compiler claims the
assertNever
is reachable (by virtue of only narrowingvalue
toRight
in the last branch).π Expected behavior
The
assertNever
is considered unreachable (that is,value
is narrowed tonever
).The text was updated successfully, but these errors were encountered: