Typescript return type for Observables in getter and setter
I think you're almost there but I question using the setter, at least in the code you have provided. When you look at the code inside your setter you're actually not setting anything to _user$.
I think this is what is tripping you up, I don't think you should be using a setter here. Based on what the code is doing inside your setter, this should just be a public function. This is what I think it should look like
constructor(private http: Http) {
this.storage = new Storage(SqlStorage);
this._user$ = new Subject();
this.dataStore = { user: {} };
}
setUser(user: User) {
this.storage.set('user', JSON.stringify(user));
this.dataStore.user = user;
this._user$.next(this.dataStore.user);
}
get user$() {
return this._user$.asObservable();
}
Then your component that is using the Service, would call UserService.setUser(userObj).
When you follow errors messages, you will have only two pairs of setter and getter:
get var(): User {}
set var(user: User) {}
And
get var(): Observable<User> {}
set var(user$: Observable<User>) {}
Actually that are the only allowed combinations.