forkJoin deprecated in RxJS v8

Lorenzo Zarantonello - Feb 3 '23 - - Dev Community

This is just a little warning for all developers using forkJoin, not a post about how to use it.
If you are looking for a coding example explaining how to use forkJoin read How To Use ForkJoin - Angular Example (free article).

Deprecation warning

In many examples, you will see syntax like the following.

forkJoin(
  of(1, 2),
  of(A, B),
)
Enter fullscreen mode Exit fullscreen mode

The code will work but the problem is that the syntax is deprecated and won't work in RxJS v8.

As reported in the documentation, passing Observables directly as parameters is deprecated.
This is called rest-parameter signature and it will be removed in RxJS v8.

RxJS suggests passing an array of sources, as below.

const sources = [of(1, 2), of(A, B)]
forkJoin(sources)
Enter fullscreen mode Exit fullscreen mode

You can find a more realistic example in How To Use ForkJoin - Angular Example (free article), but here is a preview:

sources = [
    this.http.get('https://.../users/1'),
    this.http.get('https://.../users/2'),
    this.http.get('https://.../users/3'),
  ];

  constructor(private http: HttpClient) {}

  ngOnInit() {
    forkJoin(this.sources).subscribe(console.log);
  }

Enter fullscreen mode Exit fullscreen mode

and a link to StackBlitz.

Good To Know

If you work with RxJS and you don't know the RxJS Operator Decision Tree, you should check it out. It will help you find or select the best operator for your needs.

RxJS Operator Decision Tree

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player