I have a question that I hope you can assist me with. Thank you.
Ever since the upgrade to Typescript 2.9.1, the compiler has been flagging an error for not returning the expected type in a method.
CURRENT CODE:
public getCardPairingSession(sessionId:string):Observable<FundSourceCardSessionInterface> {
const subject = new Subject();
this.apiService
.get(this.buildApiPath('card-session/' + sessionId))
.subscribe(
(response) => {
subject.next(response.result);
},
(error) => {
subject.error(error);
}
);
/* <-- ERROR: Type 'Observable<{}>' is not assignable to type 'Observable<FundSourceCardSessionInterface>' */
return subject.asObservable();
}
MY SOLUTION:
Up until now, I have been casting my return value like this, although it feels strange to me.
return <Observable<FundSourceCardSessionInterface>> subject.asObservable();
QUESTION:
If everything was working fine with Typescript 2.3.4 before, why am I facing this issue now? Why do I need to cast the return if I have already specified the expected return type at the beginning of the method? It seems redundant:
public getCardPairingSession(sessionId:string):Observable<FundSourceCardSessionInterface> {