11import { of } from 'rxjs' ;
22import { repeatWhen } from 'rxjs/operators' ;
3+ import { asInteropObservable } from '../../spec/helpers/interop-helper' ;
34
45it ( 'should infer correctly' , ( ) => {
5- const o = of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( errors => errors ) ) ; // $ExpectType Observable<number>
6+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( errors => errors ) ) ; // $ExpectType Observable<number>
67} ) ;
78
89it ( 'should infer correctly when the error observable has a different type' , ( ) => {
9- const o = of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( repeatWhen ( errors => of ( 'a' , 'b' , 'c' ) ) ) ) ; // $ExpectType Observable<number>
10+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( errors => asInteropObservable ( of ( 'a' , 'b' , 'c' ) ) ) ) ; // $ExpectType Observable<number>
1011} ) ;
1112
1213it ( 'should enforce types' , ( ) => {
13- const o = of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ) ) ; // $ExpectError
14+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ) ) ; // $ExpectError
15+ } ) ;
16+
17+ it ( 'should accept interop observable notifier' , ( ) => {
18+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => asInteropObservable ( of ( true ) ) ) ) ; // $ExpectType Observable<number>
19+ } ) ;
20+
21+ it ( 'should accept promise notifier' , ( ) => {
22+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => Promise . resolve ( true ) ) ) ; // $ExpectType Observable<number>
23+ } ) ;
24+
25+ it ( 'should async iterable notifier' , ( ) => {
26+ const asyncRange = {
27+ from : 1 ,
28+ to : 2 ,
29+ [ Symbol . asyncIterator ] ( ) {
30+ return {
31+ current : this . from ,
32+ last : this . to ,
33+ async next ( ) {
34+ await Promise . resolve ( ) ;
35+ const done = ( this . current > this . last ) ;
36+ return {
37+ done,
38+ value : done ? this . current ++ : undefined
39+ } ;
40+ }
41+ } ;
42+ }
43+ } ;
44+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => asyncRange ) ) ; // $ExpectType Observable<number>
45+ } ) ;
46+
47+ it ( 'should accept iterable notifier' , ( ) => {
48+ const syncRange = {
49+ from : 1 ,
50+ to : 2 ,
51+ [ Symbol . iterator ] ( ) {
52+ return {
53+ current : this . from ,
54+ last : this . to ,
55+ next ( ) {
56+ const done = ( this . current > this . last ) ;
57+ return {
58+ done,
59+ value : done ? this . current ++ : undefined
60+ } ;
61+ }
62+ } ;
63+ }
64+ } ;
65+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => syncRange ) ) ; // $ExpectType Observable<number>
66+ } ) ;
67+
68+ it ( 'should accept readable stream notifier' , ( ) => {
69+ const readableStream = new ReadableStream < string > ( {
70+ pull ( controller ) {
71+ controller . enqueue ( 'x' ) ;
72+ controller . close ( ) ;
73+ } ,
74+ } ) ;
75+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => readableStream ) ) ; // $ExpectType Observable<number>
1476} ) ;
1577
1678it ( 'should enforce types of the notifier' , ( ) => {
17- const o = of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => 8 ) ) ; // $ExpectError
79+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => 8 ) ) ; // $ExpectError
1880} ) ;
1981
2082it ( 'should be deprecated' , ( ) => {
21- const o = of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => of ( true ) ) ) ; // $ExpectDeprecation
83+ of ( 1 , 2 , 3 ) . pipe ( repeatWhen ( ( ) => of ( true ) ) ) ; // $ExpectDeprecation
2284} ) ;
0 commit comments