@@ -113,10 +113,6 @@ describe('Observable.prototype.last', () => {
113113 expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
114114 } ) ;
115115
116- // The current signature for last suggests that this test is not required. In
117- // fact, with type checking enabled, it will fail. See:
118- // https://github.com/ReactiveX/rxjs/issues/3717
119- /*
120116 it ( 'should support type guards without breaking previous behavior' , ( ) => {
121117 // tslint:disable no-unused-variable
122118
@@ -126,8 +122,8 @@ describe('Observable.prototype.last', () => {
126122 interface Baz { baz ?: number ; }
127123 class Foo implements Bar , Baz { constructor ( public bar : string = 'name' , public baz : number = 42 ) { } }
128124
129- const isBar = (x: any): x is Bar => x && (<Bar>x ).bar !== undefined;
130- const isBaz = (x: any): x is Baz => x && (<Baz>x ).baz !== undefined;
125+ const isBar = ( x : any ) : x is Bar => x && ( x as Bar ) . bar !== undefined ;
126+ const isBaz = ( x : any ) : x is Baz => x && ( x as Baz ) . baz !== undefined ;
131127
132128 const foo : Foo = new Foo ( ) ;
133129 of ( foo ) . pipe ( last ( ) )
@@ -164,11 +160,15 @@ describe('Observable.prototype.last', () => {
164160 // missing predicate preserves the type
165161 xs . pipe ( last ( ) ) . subscribe ( x => x ) ; // x is still string | number
166162
163+ // null predicate preserves the type
164+ xs . pipe ( last ( null ) ) . subscribe ( x => x ) ; // x is still string | number
165+
166+ // undefined predicate preserves the type
167+ xs . pipe ( last ( undefined ) ) . subscribe ( x => x ) ; // x is still string | number
168+
167169 // After the type guard `last` predicates, the type is narrowed to string
168170 xs . pipe ( last ( isString ) )
169171 . subscribe ( s => s . length ) ; // s is string
170- xs.pipe(last(isString, s => s.substr(0))) // s is string in predicate)
171- .subscribe(s => s.length); // s is string
172172
173173 // boolean predicates preserve the type
174174 xs . pipe ( last ( x => typeof x === 'string' ) )
@@ -177,5 +177,4 @@ describe('Observable.prototype.last', () => {
177177
178178 // tslint:disable enable
179179 } ) ;
180- */
181180} ) ;
0 commit comments