From f99ca49a30287d73bca3cb063ab73b191dcedf26 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Wed, 14 Sep 2016 14:04:39 +0900 Subject: [PATCH] feat(first): Observable.first() can take type guard as the predicate function --- src/operator/first.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/operator/first.ts b/src/operator/first.ts index f1cd6825c3..f07486e679 100644 --- a/src/operator/first.ts +++ b/src/operator/first.ts @@ -58,9 +58,15 @@ export function first(predicate?: (value: T, index: number, source: Observ return this.lift(new FirstOperator(predicate, resultSelector, defaultValue, this)); } +// We can cast `T -> R` in it if we pass the result selector. +// Therefore we don't provide the signature which takes both a type guard function +// as the predicate and the result selector. +// (see #1936) export interface FirstSignature { (predicate?: (value: T, index: number, source: Observable) => boolean): Observable; + (predicate?: (value: T, index: number, source: Observable) => value is S): Observable; (predicate: (value: T, index: number, source: Observable) => boolean, resultSelector: void, defaultValue?: T): Observable; + (predicate: (value: T, index: number, source: Observable) => value is S, resultSelector: void, defaultValue?: S): Observable; (predicate?: (value: T, index: number, source: Observable) => boolean, resultSelector?: (value: T, index: number) => R, defaultValue?: R): Observable; }