diff --git a/spec-dtslint/operators/filter-spec.ts b/spec-dtslint/operators/filter-spec.ts index c307c39aca..5bbcc76668 100644 --- a/spec-dtslint/operators/filter-spec.ts +++ b/spec-dtslint/operators/filter-spec.ts @@ -56,4 +56,14 @@ it('should support inference from a return type with Boolean as a predicate', () const i$: Observable = of(); const s$: Observable = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable -}); \ No newline at end of file +}); + +it('should support inference from a generic return type of the predicate', () => { + function isDefined() { + return (value: T|undefined|null): value is T => { + return value !== undefined && value !== null; + }; + } + + const o$ = of(1, null, {foo: 'bar'}, true, undefined, 'Nick Cage').pipe(filter(isDefined())); // $ExpectType Observable +}); diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index f4ce532ee2..1868f4922f 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -4,10 +4,10 @@ import { Observable } from '../Observable'; import { OperatorFunction, MonoTypeOperatorFunction, TeardownLogic } from '../types'; /* tslint:disable:max-line-length */ -// NOTE(benlesh): T|null|undefined solves the issue discussed here: https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091 -export function filter(predicate: BooleanConstructor): OperatorFunction>; export function filter(predicate: (value: T, index: number) => value is S, thisArg?: any): OperatorFunction; +// NOTE(benlesh): T|null|undefined solves the issue discussed here: https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091 +export function filter(predicate: BooleanConstructor): OperatorFunction>; export function filter(predicate: (value: T, index: number) => boolean, thisArg?: any): MonoTypeOperatorFunction; /* tslint:enable:max-line-length */