getData(): Observable<A | B> {
return this.http.get<A | B>(this.requestURL, {});
}
If I remove <A | B> syntax next to the get method, tslint emits an error saying: You can't bind Object to A or B so, I wound up adding the syntax without understanding what's going on with the syntax. I looked up Generics in Typescript and the syntax seems to be used to capture the type the user provide. What confuses me is that according to the source code of the get method in http module in Angular 5 which I'm currently using, get method declaration doesn't use generics(get method source code). Besides, if the error occurs due to the type, wouldn't return <Observable<A | B>>this.http.get(this.requestURL, {}) be correct?
To sum up, what's the point/purpose of using Generics syntax when calling a function like, get<T>() if the get method doesn't use the type information T in its declaration part?
Any insight would be appreciated!