On upgrade of rx js from 5 to 6, throws below error
[ts] Property 'filter' does not exist on type 'BehaviorSubject'.
Current Behavior
import {BehaviorSubject} from 'rxjs';
tokenSubject: BehaviorSubject<string> = new BehaviorSubject<string>(null);
return this.tokenSubject
.filter(token => token != null)
.take(1)
.switchMap(token => {
return next.handle(this.addToken(req));
});
[ts] Property 'filter' does not exist on type 'BehaviorSubject'.
Environment
"@angular/common": "^6.0.3",
"rxjs": "^6.0.0",
Expected behavior
No error and working fine
Previous Behavior
import { BehaviorSubject } from "rxjs/BehaviorSubject";
tokenSubject: BehaviorSubject<string> = new BehaviorSubject<string>(null);
return this.tokenSubject
.filter(token => token != null)
.take(1)
.switchMap(token => {
return next.handle(this.addToken(req));
});
[ts] Property 'filter' does not exist on type 'BehaviorSubject'.
Environment
"@angular/common": "^5.0.3",
"rxjs": "^5.4.3"
The RxJS v5.x to v6 Update Guide says:
The previous coding style of chaining operators has been replaced by piping the result of one operator to another.
Use the piping syntax:
return this.tokenSubject.pipe(
filter(token => token != null),
take(1),
switchMap(token => {
return next.handle(this.addToken(req));
})
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With