Skip to content
Permalink
Browse files

fix(filter): Resolve TS build failures for certain situations where B…

…oolean is the predicate
  • Loading branch information...
benlesh committed Aug 28, 2019
1 parent 6c0cbc4 commit 77c7dfd5716a1c06270bd5bbf5d0d142f3dc8043
Showing with 5 additions and 8 deletions.
  1. +1 −1 spec-dtslint/operators/filter-spec.ts
  2. +4 −7 src/internal/operators/filter.ts
@@ -55,5 +55,5 @@ it('should support inference from a return type with Boolean as a predicate', ()
}

const i$: Observable<I> = of();
const s$ = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable<string>
const s$: Observable<string> = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable<string>
});
@@ -4,7 +4,8 @@ import { Observable } from '../Observable';
import { OperatorFunction, MonoTypeOperatorFunction, TeardownLogic } from '../types';

/* tslint:disable:max-line-length */
export function filter<T>(predicate: BooleanConstructor): OperatorFunction<T, NonNullable<T>>;
// NOTE(benlesh): T|null|undefined solves the issue discussed here: https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091
export function filter<T>(predicate: BooleanConstructor): OperatorFunction<T|null|undefined, NonNullable<T>>;
export function filter<T, S extends T>(predicate: (value: T, index: number) => value is S,
thisArg?: any): OperatorFunction<T, S>;
export function filter<T>(predicate: (value: T, index: number) => boolean,
@@ -43,18 +44,14 @@ export function filter<T>(predicate: (value: T, index: number) => boolean,
* @see {@link partition}
* @see {@link skip}
*
* @param {function(value: T, index: number): boolean} predicate A function that
* @param predicate A function that
* evaluates each value emitted by the source Observable. If it returns `true`,
* the value is emitted, if `false` the value is not passed to the output
* Observable. The `index` parameter is the number `i` for the i-th source
* emission that has happened since the subscription, starting from the number
* `0`.
* @param {any} [thisArg] An optional argument to determine the value of `this`
* @param thisArg An optional argument to determine the value of `this`
* in the `predicate` function.
* @return {Observable} An Observable of values from the source that were
* allowed by the `predicate` function.
* @method filter
* @owner Observable
*/
export function filter<T>(predicate: (value: T, index: number) => boolean,
thisArg?: any): MonoTypeOperatorFunction<T> {

0 comments on commit 77c7dfd

Please sign in to comment.
You can’t perform that action at this time.