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
{{ message }}
Repository navigation
Type guards are not working properly in Observable #19334
import{Observable}from'rxjs/Observable';import'rxjs/add/observable/from';import'rxjs/add/operator/filter';typeAType='first'|'second';functionisFirst(value: AType): value is 'first'{returnvalue==='first';}constinputs: AType[]=['first','second'];constobx=Observable.from(inputs);obx.filter(item=>isFirst(item))// <- checking types with guard.subscribe(item=>console.log(item));// <- here item is still `'first' | 'second'`!
Expected behavior:
Type guards must make sure the flow continues according to the current status of types.
Actual behavior:
Apparently because the type guard is not within a branch it is not working as intended, or it is working as intended by design that I personally think is not a good idea.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
aminpaks commentedon Oct 20, 2017
Andy (Andrewkraft) (@Andy-MS) I'm using
[email protected], and tried with5.5.0but no difference!from rxjs:
aminpaks commentedon Oct 20, 2017
I found this issue. Is this a duplication?
aminpaks commentedon Oct 20, 2017
Andy (Andrewkraft) (@Andy-MS) you're missing the
from->import 'rxjs/add/observable/from'aminpaks commentedon Oct 20, 2017
I updated my question :)
aminpaks commentedon Oct 20, 2017
Andy (Andrewkraft) (@Andy-MS) that's interesting! Thanks a lot.
mhegazy commentedon Nov 6, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.