Skip to content

Commit

Permalink
feat(startWith): allow different types
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Aug 21, 2018
1 parent 4416884 commit a852868
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions spec-dtslint/operators/startWith-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>
});

it('should infer correctly with only a scheduler', () => {
const o = of(1, 2, 3).pipe(startWith(asyncScheduler)); // $ExpectType Observable<number>
it('should infer correctly with a different type', () => {
const o = of(1, 2, 3).pipe(startWith('foo')); // $ExpectType Observable<string | number>
});

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<string | number | boolean>
});

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<number>
});
18 changes: 9 additions & 9 deletions src/internal/operators/startWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, v2: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, v2: T, v3: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, v2: T, v3: T, v4: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, v2: T, v3: T, v4: T, v5: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(v1: T, v2: T, v3: T, v4: T, v5: T, v6: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>;
export function startWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T>;
export function startWith<T, D = T>(v1: D, scheduler?: SchedulerLike): OperatorFunction<T, T | D>;
export function startWith<T, D = T, E = T>(v1: D, v2: E, scheduler?: SchedulerLike): OperatorFunction<T, T | D | E>;
export function startWith<T, D = T, E = T, F = T>(v1: D, v2: E, v3: F, scheduler?: SchedulerLike): OperatorFunction<T, T | D | E | F>;
export function startWith<T, D = T, E = T, F = T, G = T>(v1: D, v2: E, v3: F, v4: G, scheduler?: SchedulerLike): OperatorFunction<T, T | D | E | F | G>;
export function startWith<T, D = T, E = T, F = T, G = T, H = T>(v1: D, v2: E, v3: F, v4: G, v5: H, scheduler?: SchedulerLike): OperatorFunction<T, T | D | E | F | G | H>;
export function startWith<T, D = T, E = T, F = T, G = T, H = T, I = T>(v1: D, v2: E, v3: F, v4: G, v5: H, v6: I, scheduler?: SchedulerLike): OperatorFunction<T, T | D | E | F | G | H | I>;
export function startWith<T, D = T>(...array: Array<D | SchedulerLike>): OperatorFunction<T, T | D>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ export function startWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperat
* @method startWith
* @owner Observable
*/
export function startWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
export function startWith<T, D>(...array: Array<T | SchedulerLike>): OperatorFunction<T, T | D> {
return (source: Observable<T>) => {
let scheduler = <SchedulerLike>array[array.length - 1];
if (isScheduler(scheduler)) {
Expand Down

0 comments on commit a852868

Please sign in to comment.