ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.7k stars 3k forks source link

this.project is not a function #2688

Closed haf closed 7 years ago

haf commented 7 years ago

RxJS version: 5.4.0

Code to reproduce:

import { Observable } from 'rxjs/Rx';
const SEND_RESET = "sr";
function successOf(x) { return `${x}_SUCCESS` }
const WaitUntilRedirect = 10;
export function resetRedirectAfterSend(action$: Observable) {
  return action$.ofType(successOf(SEND_RESET)).concatMap(
    Observable
      .range(0, WaitUntilRedirect)
      .delay(
        Observable.timer(1000),
        x => Observable.timer(x * 1000))
      .timeInterval()
      .map(x => setUntilRedirect(WaitUntilRedirect - x.interval * x.value))
      .concatMap(action => push({
        pathname: '/accounts/login',
        query: {
          scent: 'forgot'
        }
      }))
  );
}

Expected behavior: No crash

Actual behavior:

VM224378:242 Uncaught TypeError: this.project is not a function
    at MergeMapSubscriber._tryNext (eval at ./node_modules/rxjs/operator/mergeMap.js (app.js:9085), <anonymous>:120:27)
    at MergeMapSubscriber._next (eval at ./node_modules/rxjs/operator/mergeMap.js (app.js:9085), <anonymous>:110:18)
    at MergeMapSubscriber.Subscriber.next (eval at ./node_modules/rxjs/Subscriber.js (app.js:7269), <anonymous>:89:18)
    at FilterSubscriber._next (eval at ./node_modules/rxjs/operator/filter.js (app.js:8957), <anonymous>:88:30)
    at FilterSubscriber.Subscriber.next (eval at ./node_modules/rxjs/Subscriber.js (app.js:7269), <anonymous>:89:18)
    at Subject.next (eval at ./node_modules/rxjs/Subject.js (app.js:7253), <anonymous>:55:25)
    at eval (eval at ./node_modules/redux-observable/lib/es/createEpicMiddleware.js (app.js:7078), <anonymous>:69:16)
    at eval (eval at ./app/components/logging/mixpanel.js (app.js:713), <anonymous>:157:16)
    at eval (eval at ./node_modules/react-router-redux/es/middleware.js (app.js:6680), <anonym

Additional information:

kwonoj commented 7 years ago
.concatMap(
    Observable
      .range(0, WaitUntilRedirect)

-> concatMap(project: (value: T, index: number) => ObservableInput<I>) (https://github.com/ReactiveX/rxjs/blob/master/src/operator/concatMap.ts#L68)

haf commented 7 years ago

You're right. What threw me off is the error message; while I did not properly use the functions, it should not crash internally like this.

kwonoj commented 7 years ago

it's quite similar cases to https://github.com/ReactiveX/rxjs/issues/2144#issuecomment-261801399. Nature of javascript is dynamic and you can provide / call nearly every possible way, in most cases we can't prevent all cases in runtime check. That's reason we're providing TS definition as documented api interface - even user of javascript can refer those interfaces.

haf commented 7 years ago

@kwonoj What's wrong with the code you linked? Your docs state I can supply an observable to concat map (third example here https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/concatmap.md#rxobservableprototypeconcatmapselector-resultselector-thisarg)

source.concatMap(Rx.Observable.of(1,2,3));
source.concatMap(Promise.resolve(42));
source.concatMap([1,2,3]);
kwonoj commented 7 years ago

document you referred is rxjs4, 5 has breaking changes and not compatible.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.