I'm building a typescript angular 2 app and using rxjs. I am following the example here:
https://angular.io/docs/ts/latest/tutorial/toh-pt6.html#!#stq=formgroup&stp=1
All though I am trying to strongly type my return signatures with typescript. This may be my problem in that you aren't supposed to. But it seems like you should be able to.
Suppose I have service that is typed to return an Observable>.
public search(term: string) : Observable<Array<MyModel>> { // http call }
In my component I am attempting to listen to this observable stream and return the results.
private search = new Subject<Search>();
results: Observable<Array<MyModel>>;
ngOnInit() {
this.results = this.search
.debounceTime(400)
.distinctUntilChanged()
.switchMap(search => {
return service.search(search.term); // returns Observable<Array<MyModel>>
});
}
This doesn't compile with the message Cannot convert type Observable<Object> to type Observable<MyModel[]>>
I don't understand why switchmap is returning an Observable instead of my type. Do I need to map it again before giving it to results? Is this a typescript typings issue with the return signature of switchmap?