From ad951b13b95e1f1a99291ff03cea59032e5a64dc Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Thu, 15 Oct 2020 23:49:17 +0200 Subject: [PATCH] feat(filter): improve type inference for filter(Boolean) --- api_guard/dist/types/operators/index.d.ts | 2 +- spec-dtslint/operators/filter-spec.ts | 2 +- src/internal/operators/filter.ts | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api_guard/dist/types/operators/index.d.ts b/api_guard/dist/types/operators/index.d.ts index b707aab65ff..66f43cdba6c 100644 --- a/api_guard/dist/types/operators/index.d.ts +++ b/api_guard/dist/types/operators/index.d.ts @@ -109,7 +109,7 @@ export declare function expand(project: (value: T, index: number) => Obser export declare function expand(project: (value: T, index: number) => ObservableInput, concurrent: number | undefined, scheduler: SchedulerLike): OperatorFunction; export declare function filter(predicate: (value: T, index: number) => value is S, thisArg?: any): OperatorFunction; -export declare function filter(predicate: BooleanConstructor): OperatorFunction>; +export declare function filter(predicate: BooleanConstructor): OperatorFunction; export declare function filter(predicate: (value: T, index: number) => boolean, thisArg?: any): MonoTypeOperatorFunction; export declare function finalize(callback: () => void): MonoTypeOperatorFunction; diff --git a/spec-dtslint/operators/filter-spec.ts b/spec-dtslint/operators/filter-spec.ts index 5bbcc76668f..d2320585ebf 100644 --- a/spec-dtslint/operators/filter-spec.ts +++ b/spec-dtslint/operators/filter-spec.ts @@ -51,7 +51,7 @@ it('should support Boolean as a predicate', () => { // https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091 it('should support inference from a return type with Boolean as a predicate', () => { interface I { - a: string | null; + a: string | null | undefined | false | 0 | 0n | ''; } const i$: Observable = of(); diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index 050dc7b0278..a5f44357cdb 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -5,8 +5,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; /* tslint:disable:max-line-length */ 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: BooleanConstructor): OperatorFunction; export function filter(predicate: (value: T, index: number) => boolean, thisArg?: any): MonoTypeOperatorFunction; /* tslint:enable:max-line-length */