menu

Questions & Answers

Argument of type 'BehaviorSubject<MediaSuffix>' is not assignable to parameter of type 'Observable<MediaSuffix>'

There is an error in one my spec files:

const a = jasmine.createSpyObj<AppService>('as', ['getAppsForUserByRoleObservable']); const msMock = jasmine.createSpyObj<MediaService>('ms', ['getMediaSuffix']); const observable = new BehaviorSubject(MediaSuffix.Lg); msMock.getMediaSuffix.and.returnValue(observable);

It showing an error for "observable" on the last line. Putting my cursor over gives this error: "Argument of type 'BehaviorSubject' is not assignable to parameter of type 'Observable'. Type 'BehaviorSubject' is missing the following properties from type 'Observable': _isScalar, _trySubscribe, _subscribe"

the code

the error message

How do I fix this?

I have tried adding an "of" from rxjs, but it did not work.

Comments:
2023-01-21 00:42:03
To fix this, you can convert the BehaviorSubject to an Observable using asObservable()
Answers(0) :