From a852868aa791cc710d8b1512957ca27bf1a85175 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Tue, 21 Aug 2018 09:02:19 +0200 Subject: [PATCH] feat(startWith): allow different types --- spec-dtslint/operators/startWith-spec.ts | 12 ++++++------ src/internal/operators/startWith.ts | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spec-dtslint/operators/startWith-spec.ts b/spec-dtslint/operators/startWith-spec.ts index 4cf78c0b92..5b4a9f5322 100644 --- a/spec-dtslint/operators/startWith-spec.ts +++ b/spec-dtslint/operators/startWith-spec.ts @@ -17,14 +17,14 @@ it('should infer correctly with a value and a scheduler', () => { const o = of(1, 2, 3).pipe(startWith(5, asyncScheduler)); // $ExpectType Observable }); -it('should infer correctly with only a scheduler', () => { - const o = of(1, 2, 3).pipe(startWith(asyncScheduler)); // $ExpectType Observable +it('should infer correctly with a different type', () => { + const o = of(1, 2, 3).pipe(startWith('foo')); // $ExpectType Observable }); -it('should enforce types with one value', () => { - const o = of(1, 2, 3).pipe(startWith('foo')); // $ExpectError +it('should infer correctly with multiple different types', () => { + const o = of(1, 2, 3).pipe(startWith('foo', 4, true)); // $ExpectType Observable }); -it('should enforce types with multiple value', () => { - const o = of(1, 2, 3).pipe(startWith(4, 'foo')); // $ExpectError +it('should infer correctly with only a scheduler', () => { + const o = of(1, 2, 3).pipe(startWith(asyncScheduler)); // $ExpectType Observable }); diff --git a/src/internal/operators/startWith.ts b/src/internal/operators/startWith.ts index 528ffbfcde..6850bdc98d 100644 --- a/src/internal/operators/startWith.ts +++ b/src/internal/operators/startWith.ts @@ -4,17 +4,17 @@ import { scalar } from '../observable/scalar'; import { empty } from '../observable/empty'; import { concat as concatStatic } from '../observable/concat'; import { isScheduler } from '../util/isScheduler'; -import { MonoTypeOperatorFunction, SchedulerLike } from '../types'; +import { MonoTypeOperatorFunction, OperatorFunction, SchedulerLike } from '../types'; /* tslint:disable:max-line-length */ export function startWith(scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, v2: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, v2: T, v3: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, v2: T, v3: T, v4: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, v2: T, v3: T, v4: T, v5: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(v1: T, v2: T, v3: T, v4: T, v5: T, v6: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction; -export function startWith(...array: Array): MonoTypeOperatorFunction; +export function startWith(v1: D, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(v1: D, v2: E, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(v1: D, v2: E, v3: F, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(v1: D, v2: E, v3: F, v4: G, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(v1: D, v2: E, v3: F, v4: G, v5: H, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I, scheduler?: SchedulerLike): OperatorFunction; +export function startWith(...array: Array): OperatorFunction; /* tslint:enable:max-line-length */ /** @@ -49,7 +49,7 @@ export function startWith(...array: Array): MonoTypeOperat * @method startWith * @owner Observable */ -export function startWith(...array: Array): MonoTypeOperatorFunction { +export function startWith(...array: Array): OperatorFunction { return (source: Observable) => { let scheduler = array[array.length - 1]; if (isScheduler(scheduler)) {