Here is a generic function to consider:
public getData<T>(url: string): Observable<T> {
return this.httpClient.get<T>(url);
}
I am looking for a way to test this function by returning a mock object array, especially if the remote API is not available yet.
This is what I want to return:
return of([{id: 1, value: 'test1'}, {id: 2, value: 'test2'}]);
However, when I try to do this, I encounter an error:
TS2322: Type 'Observable<{ id: number; value: string; }[]>' is not assignable to type 'Observable'. Type '{ id: number; value: string; }[]' is not assignable to type 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to '{ id: number; value: string; }[]'.
Is there a way to resolve this issue?