Closed
Description
TypeScript Version: 2.5.3
Code
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/filter';
type AType = 'first' | 'second';
function isFirst(value: AType): value is 'first' {
return value === 'first';
}
const inputs: AType[] = ['first', 'second'];
const obx = Observable.from(inputs);
obx
.filter(item => isFirst(item)) // <- checking types with guard
.subscribe(item => console.log(item)); // <- here item is still `'first' | 'second'`!
A simple example to reproduce.
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.