1
- import { of } from 'rxjs' ;
2
- import { filter } from 'rxjs/operators' ;
1
+ import { Observable , of } from 'rxjs' ;
2
+ import { filter , map } from 'rxjs/operators' ;
3
3
4
4
it ( 'should support a predicate' , ( ) => {
5
5
const o = of ( 1 , 2 , 3 ) . pipe ( filter ( value => value < 3 ) ) ; // $ExpectType Observable<number>
@@ -38,3 +38,22 @@ it('should enforce user-defined type guard types', () => {
38
38
const o = of ( 1 , 2 , 3 ) . pipe ( filter ( ( value : string ) : value is '1' => value < '3' ) ) ; // $ExpectError
39
39
const p = of ( 1 , 2 , 3 ) . pipe ( filter ( ( value : number , index ) : value is 1 => index < '3' ) ) ; // $ExpectError
40
40
} ) ;
41
+
42
+ it ( 'should support Boolean as a predicate' , ( ) => {
43
+ const o = of ( 1 , 2 , 3 ) . pipe ( filter ( Boolean ) ) ; // $ExpectType Observable<number>
44
+ const p = of ( 1 , null , undefined ) . pipe ( filter ( Boolean ) ) ; // $ExpectType Observable<number>
45
+ const q = of ( null , undefined ) . pipe ( filter ( Boolean ) ) ; // $ExpectType Observable<never>
46
+ } ) ;
47
+
48
+ // I've not been able to effect a failing dtslint test for this situation and a
49
+ // conventional test won't fail because the TypeScript configuration isn't
50
+ // sufficiently strict:
51
+ // https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091
52
+ it ( 'should support inference from a return type with Boolean as a predicate' , ( ) => {
53
+ interface I {
54
+ a : string | null ;
55
+ }
56
+
57
+ const i$ : Observable < I > = of ( ) ;
58
+ const s$ : Observable < string > = i$ . pipe ( map ( i => i . a ) , filter ( Boolean ) ) ; // $ExpectType Observable<string>
59
+ } ) ;
0 commit comments