Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rxjs 7 update - Subject - Expected 1 arguments, but got 0

I updated rxjs from version 6.x.x to 7.x.x, but following error appeared:

Error in src/app/app.component.ts (12:19) Expected 1 arguments, but got 0.

when trying to next an empty value to the Subject

destroy$ = new Subject();

constructor() {
  this.destroy$.next(); // <-- Expected 1 arguments, but got 0.
}

Error stackblitz

like image 314
eko Avatar asked Jul 30 '21 12:07

eko


Video Answer


1 Answers

tl;dr:

Either typecast it with void:

new Subject<void>();

or pass a fake value:

this.destroy$.next(true);

Rxjs 7 changes

After checking the changelog and several github issues about this situation,

Subject: resolve issue where Subject constructor errantly allowed an argument (#5476) (e1d35dc)

Subject: no default generic (e678e81)

Changelog 7.0.0-beta.1 and the commit where empty value is removed from the tests

enter image description here

I realized that the solution was to either provide a value or simply typecast the Subject with <void> as in destroy$ = new Subject<void>() if you want to next it with an empty value.

like image 184
eko Avatar answered Oct 09 '22 11:10

eko