Skip to content

Commit 77c7dfd

Browse files
committed
fix(filter): Resolve TS build failures for certain situations where Boolean is the predicate
1 parent 6c0cbc4 commit 77c7dfd

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

spec-dtslint/operators/filter-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ it('should support inference from a return type with Boolean as a predicate', ()
5555
}
5656

5757
const i$: Observable<I> = of();
58-
const s$ = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable<string>
58+
const s$: Observable<string> = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable<string>
5959
});

src/internal/operators/filter.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Observable } from '../Observable';
44
import { OperatorFunction, MonoTypeOperatorFunction, TeardownLogic } from '../types';
55

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

0 commit comments

Comments
 (0)