As a newcomer to TypeScript, I recently discovered how useful it is to map an HTTP response to a class. For example:
getMovies(): Observable<Movie[]> {
return this.http.get<Movie[]>(this.endpoint);
}
This allows me to receive a populated array of Movie
classes. Inspired by this functionality, I decided to explore the idea of creating a more general method by utilizing a supposed get
function in a parent class:
// child
getMovies(): Observable<Movie[]> {
return this.super.get(class_reference_here, this.endpoint);
}
// parent
get(reference: any, endpoint: string): Observable<any> /* or <any[]> ?? */ {
return this.http.get<reference[]>(endpoint);
}
I am curious if it's possible to implement something like this. How can I populate class_reference_here
with a meaningful value? Does this approach align with TypeScript principles, or does it raise concerns? Your guidance would be immensely valuable.