question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking change in SwitchMap 6.3.3 -> 6.4.0

See original GitHub issue

Documentation Related To Component:

SwitchMap

Please check those that apply

  • typo
  • documentation doesn’t exist
  • documentation needs clarification
  • error(s) in example
  • needs example

Description Of The Issue

Version 6.4.0 contains a breaking change when coming from 6.3.3 that is not mentioned in the CHANGELOG.md. The culprit is this change:

switchMap: support union type returns (32d35fd)

This introduced a breaking change if you used the generic types

Before:

switchMap<string, Foo[]>(...)

After:

switchMap<string, Observable<Foo[]>>(...)

I also spotted something odd here https://github.com/reactivex/rxjs/commit/32d35fd#diff-2890e8018eeca17541f08afe9bc0bc2eL9

The test says “should support a projector that takes an index” but the index parameter was removed. That doesn’t look right to me. I’m assuming prettier or something like that removed the unused parameter 🤔

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
benleshcommented, Apr 10, 2019

Core Team Meeting Notes

SInce using the generic arguments to cast is really an anti-pattern in TypeScript in general, We will:

  • Document what to do when you need to cast an operator
  • Introduce a new type to make it more ergonomic to cast at various points in the pipe chain when developers encounter problems, for example:
source$.pipe(
  switchMap(fn) as RxOp<number>,     // effectivly OperatorFunction<any, number>
  map(n => n + n),                   // fine because of the cast above
)

It’s an issue for people, but the generics changes were to fix other bugs with typings in the library, and we don’t want to undo that, because we would be punishing people who were indeed using the library properly. So we’ll prioritize getting this new type out there and documenting it.

2reactions
alex-okrushkocommented, Apr 23, 2019

@snebjorn If you really need to provide an explicit type (instead of inferred) I suggest to specify it in the return type of the function:

instead of

const obs = of(3).pipe(
  switchMap<number, string>(x => of('3'))
);

use

const obs = of(3).pipe(
  switchMap((x): Observable<string> => of('3'))
);

it works in both 6.3.3 and 6.4.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

when I update rxjs from 6.3.3 to 6.4.0, I get the error: ...
After updating to rxjs 6.4.0, I get the error: ERROR TypeError: You provided an invalid object where a stream was expected. You can...
Read more >
rxjs/CHANGELOG.md
272, ### BREAKING CHANGES. 273. 274, - **windowToggle:** the observable returned by the windowToggle operator's. 275, closing selector must emit a next ...
Read more >
rxjs
This is a rewrite of Reactive-Extensions/RxJS and is the latest production-ready version of RxJS. This rewrite is meant to have better ...
Read more >
@reactivex/rxjs | Yarn - Package Manager
0 (2018-03-16) ... BREAKING CHANGES. ajax: will no longer execute a CORS request by default, you must opt-in with the crossDomain flag in...
Read more >
switchMap
Each time it observes one of these inner Observables, the output Observable begins emitting the items emitted by that inner Observable. When a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found