diff --git a/spec/operators/reduce-spec.ts b/spec/operators/reduce-spec.ts index 427342a77e..603dda87ef 100644 --- a/spec/operators/reduce-spec.ts +++ b/spec/operators/reduce-spec.ts @@ -316,6 +316,33 @@ describe('Observable.prototype.reduce', () => { }); }); + it('should accept T typed reducers when T is an array', () => { + type(() => { + let a: Rx.Observable; + const reduced = a.reduce((acc, value) => { + return acc.concat(value); + }, []); + + reduced.subscribe(rs => { + rs[0].toExponential(); + }); + }); + }); + + it('should accept R typed reduces when R is an array of T', () => { + type(() => { + let a: Rx.Observable; + const reduced = a.reduce((acc, value) => { + acc.push(value); + return acc; + }, []); + + reduced.subscribe(rs => { + rs[0].toExponential(); + }); + }); + }); + it('should accept R typed reducers when R is assignable to T', () => { type(() => { let a: Rx.Observable<{ a?: number; b?: string }>; diff --git a/src/operator/reduce.ts b/src/operator/reduce.ts index aefb943955..9cbb638781 100644 --- a/src/operator/reduce.ts +++ b/src/operator/reduce.ts @@ -3,8 +3,8 @@ import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; /* tslint:disable:max-line-length */ -export function reduce(this: Observable, accumulator: (acc: T[], value: T, index: number) => T[], seed: T[]): Observable; export function reduce(this: Observable, accumulator: (acc: T, value: T, index: number) => T, seed?: T): Observable; +export function reduce(this: Observable, accumulator: (acc: T[], value: T, index: number) => T[], seed: T[]): Observable; export function reduce(this: Observable, accumulator: (acc: R, value: T, index: number) => R, seed: R): Observable; /* tslint:enable:max-line-length */