Skip to content

Instantly share code, notes, and snippets.

@armanozak
Created May 3, 2021 08:46
Show Gist options
  • Save armanozak/1038db6db73803037d4a7225c70903ae to your computer and use it in GitHub Desktop.
Save armanozak/1038db6db73803037d4a7225c70903ae to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] Better types in groups created by groupBy #blog #rxjs
import { of } from "rxjs";
import { groupBy, map, mergeMap } from "rxjs/operators";
// Observable<string, number>
of(0, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9, "...")
.pipe(
groupBy((x): x is number => typeof x === "number"),
mergeMap(group$ => (group$.key === true ? group$.pipe(map(String)) : group$))
)
.subscribe();
// Observable<string> (in RxJS 6 → Observable<string | number>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment