From 6c0cbc419bb65734e6836e1b3b64e738310e94d3 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 27 Aug 2019 19:30:52 -0500 Subject: [PATCH] feat(concat): can infer N types - Removes superfluous return typing - Updates deprecation messages BREAKING CHANGE: `concat` generic signature changed. Recommend not explicitly passing generics, just let inference do its job. If you must, cast with `as`. --- spec-dtslint/observables/concat-spec.ts | 2 +- src/internal/observable/concat.ts | 44 +++++++++---------------- src/internal/operators/concat.ts | 2 +- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/spec-dtslint/observables/concat-spec.ts b/spec-dtslint/observables/concat-spec.ts index 6549c2551f..e29155a6d5 100644 --- a/spec-dtslint/observables/concat-spec.ts +++ b/spec-dtslint/observables/concat-spec.ts @@ -29,7 +29,7 @@ it('should accept more than 6 params', () => { }); it('should return Observable for more than 6 different types of params', () => { - const o = concat(of(1), of('a'), of(2), of(true), of(3), of([1, 2, 3]), of(4)); // $ExpectType Observable + const o = concat(of(1), of('a'), of(2), of(true), of(3), of([1, 2, 3]), of(4)); // $ExpectType Observable }); it('should accept scheduler after params', () => { diff --git a/src/internal/observable/concat.ts b/src/internal/observable/concat.ts index 03bb07658f..135f479002 100644 --- a/src/internal/observable/concat.ts +++ b/src/internal/observable/concat.ts @@ -1,34 +1,24 @@ import { Observable } from '../Observable'; -import { ObservableInput, SchedulerLike, ObservedValueOf } from '../types'; +import { ObservableInput, SchedulerLike, ObservedValueOf, ObservedValuesFromArray } from '../types'; import { of } from './of'; import { concatAll } from '../operators/concatAll'; /* tslint:disable:max-line-length */ -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat>(v1: O1, scheduler: SchedulerLike): Observable>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat, O2 extends ObservableInput>(v1: O1, v2: O2, scheduler: SchedulerLike): Observable | ObservedValueOf>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat, O2 extends ObservableInput, O3 extends ObservableInput>(v1: O1, v2: O2, v3: O3, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ +/** @deprecated remove in v8. Passing a scheduler to concat is deprecated, please use {@link scheduled} and {@link concatAll} `scheduled([o1, o2], scheduler).pipe(concatAll())` */ export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, scheduler: SchedulerLike): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -export function concat>(v1: O1): Observable>; -export function concat, O2 extends ObservableInput>(v1: O1, v2: O2): Observable | ObservedValueOf>; -export function concat, O2 extends ObservableInput, O3 extends ObservableInput>(v1: O1, v2: O2, v3: O3): Observable | ObservedValueOf | ObservedValueOf>; -export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -export function concat, O2 extends ObservableInput, O3 extends ObservableInput, O4 extends ObservableInput, O5 extends ObservableInput, O6 extends ObservableInput>(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6): Observable | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf | ObservedValueOf>; -export function concat>(...observables: O[]): Observable>; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ -export function concat>(...observables: (O | SchedulerLike)[]): Observable>; -export function concat(...observables: ObservableInput[]): Observable; -/** @deprecated Use {@link scheduled} and {@link concatAll} (e.g. `scheduled([o1, o2, o3], scheduler).pipe(concatAll())`) */ -export function concat(...observables: (ObservableInput | SchedulerLike)[]): Observable; +export function concat[]>(...observables: A): Observable>; + /* tslint:enable:max-line-length */ /** * Creates an output Observable which sequentially emits all values from given @@ -127,17 +117,13 @@ export function concat(...observables: (ObservableInput | SchedulerLike) * @see {@link concatMap} * @see {@link concatMapTo} * - * @param {ObservableInput} input1 An input Observable to concatenate with others. - * @param {ObservableInput} input2 An input Observable to concatenate with others. + * @param input1 An input Observable to concatenate with others. + * @param input2 An input Observable to concatenate with others. * More than one input Observables may be given as argument. - * @param {SchedulerLike} [scheduler=null] An optional {@link SchedulerLike} to schedule each + * @param scheduler An optional {@link SchedulerLike} to schedule each * Observable subscription on. - * @return {Observable} All values of each passed Observable merged into a - * single Observable, in order, in serial fashion. - * @static true - * @name concat - * @owner Observable */ -export function concat, R>(...observables: Array): Observable | R> { - return concatAll()(of(...observables) as Observable>); +export function concat>(...observables: Array): Observable> { + // The cast with `as` below is due to the SchedulerLike, once this is removed, it will no longer be a problem. + return concatAll>()(of(...observables) as Observable>); } diff --git a/src/internal/operators/concat.ts b/src/internal/operators/concat.ts index aee64666f9..46871cccee 100644 --- a/src/internal/operators/concat.ts +++ b/src/internal/operators/concat.ts @@ -25,5 +25,5 @@ export function concat(...observables: Array | Schedu * @deprecated Deprecated in favor of static {@link concat}. */ export function concat(...observables: Array | SchedulerLike>): OperatorFunction { - return (source: Observable) => source.lift.call(concatStatic(source, ...observables)); + return (source: Observable) => source.lift.call(concatStatic(source, ...(observables as any[]))); }