Skip to content

Commit

Permalink
fix(find): add undefined to return type
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Jul 28, 2018
1 parent 5c52a73 commit a9c06f4
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/internal/operators/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import {Subscriber} from '../Subscriber';
import {OperatorFunction, MonoTypeOperatorFunction} from '../types';

export function find<T, S extends T>(predicate: (value: T, index: number, source: Observable<T>) => value is S,
thisArg?: any): OperatorFunction<T, S>;
export function find<T, S extends T>(predicate: (value: T, index: number) => value is S,
thisArg?: any): OperatorFunction<T, S>;
thisArg?: any): OperatorFunction<T, S | undefined>;
export function find<T>(predicate: (value: T, index: number, source: Observable<T>) => boolean,
thisArg?: any): MonoTypeOperatorFunction<T>;
export function find<T>(predicate: (value: T, index: number) => boolean,
thisArg?: any): MonoTypeOperatorFunction<T>;
thisArg?: any): MonoTypeOperatorFunction<T | undefined>;
/**
* Emits only the first value emitted by the source Observable that meets some
* condition.
Expand Down Expand Up @@ -48,14 +44,14 @@ export function find<T>(predicate: (value: T, index: number) => boolean,
* @owner Observable
*/
export function find<T>(predicate: (value: T, index: number, source: Observable<T>) => boolean,
thisArg?: any): MonoTypeOperatorFunction<T> {
thisArg?: any): OperatorFunction<T, T | undefined> {
if (typeof predicate !== 'function') {
throw new TypeError('predicate is not a function');
}
return (source: Observable<T>) => source.lift(new FindValueOperator(predicate, source, false, thisArg));
return (source: Observable<T>) => source.lift(new FindValueOperator(predicate, source, false, thisArg)) as Observable<T | undefined>;
}

export class FindValueOperator<T> implements Operator<T, T> {
export class FindValueOperator<T> implements Operator<T, T | number | undefined> {
constructor(private predicate: (value: T, index: number, source: Observable<T>) => boolean,
private source: Observable<T>,
private yieldIndex: boolean,
Expand Down

0 comments on commit a9c06f4

Please sign in to comment.