Rxjs: 6.5.x endWith() Regression

Created on 1 May 2019  路  1Comment  路  Source: ReactiveX/rxjs

Bug Report

Current Behavior
endWith throws TypeError.

TypeError: You provided '2' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Reproduction
https://jsfiddle.net/1Lz8m4bx/1/

 of(1).pipe(endWith(2)).subscribe(console.log);

Expected behavior
Should not throw :)

Environment

  • Runtime: Chrome latest
  • RxJS version: 6.5.1 (seems to be in 6.5.0 as well)

Possible Solution
After investigating a bit, I believe this line in the implementation of endWith isn't quite right:

// current implemention:
export function endWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
  return (source: Observable<T>) => concat(source, ...(array as any[])) as Observable<T>;
}

// Maybe something like this (I wouldn't be surprised if that allows the removal of the type assertion):
export function endWith<T>(...array: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
  return (source: Observable<T>) => concat(source, of(...array)) as Observable<T>;
}

Most helpful comment

Closing, as this appears to be a dupe of the issue resolved in https://github.com/ReactiveX/rxjs/pull/4735

>All comments

Closing, as this appears to be a dupe of the issue resolved in https://github.com/ReactiveX/rxjs/pull/4735

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zzzen picture Zzzen  路  3Comments

samherrmann picture samherrmann  路  3Comments

unao picture unao  路  4Comments

benlesh picture benlesh  路  3Comments

benlesh picture benlesh  路  3Comments