DEV Community

Cover image for forkJoin deprecated in RxJS v8
Lorenzo Zarantonello for This is Angular

Posted on • Originally published at Medium

forkJoin deprecated in RxJS v8

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

Top comments (6)

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

On Docs that's still not marked as breaking for V8, but maybe it will be.
And further option is to use a map {name1: source1; name2: source2} as argument.In any case, it will affect combineLatest too.
Obviously talking about static function.
The homonymous operator will be definitely dropped in favor of combineLatestWith.

Collapse
 
lorenzojkrl profile image
Lorenzo Zarantonello

Seems likely to happen. I might write more about RxJS.
Thanks for adding value here!

Collapse
 
calinzbaenen profile image
Calin Baenen

On Docs that's still not marked as breaking for V8, but maybe it will be.

That's usually what deprecation is.
The state between the breaking change of something being removed and it being in existence.

Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Yes, but breaking changes for v8 have not been published yet, so saying that "It will not work" is likely but not certain.
The only thing that makes the assertion more valuable is the listing of removing of every long-deprecated API as a step inside roadmap, considering that signature has been deprecated years ago.

Collapse
 
hakimio profile image
Tomas Rimkus

That usage is deprecated since 6.5. It might be removed in v8, not just deprecated.

Collapse
 
citronbrick profile image
CitronBrick

To enable JS syntax highlighting, you can use

(triple backtick) javascript