Below is a class that I have:
export class RestService {
private baseUrl: string;
constructor(protected http: HttpClient) {
this.baseUrl = environment.LOCAL_URL;
}
public get<T>(resource: string, params?: HttpParams): Observable<T> {
const url = this.PrepareUrl(resource);
return this.http.get<T>(url, { params }).pipe(
retry(2),
catchError(this.catchBadResponse)
);
}
public post<T>(resource: string, model: any): Observable<T> {
const url = this.PrepareUrl(resource);
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
return this.http.post<T>(url, model, { headers }).pipe(
retry(2),
catchError(this.catchBadResponse)
);
}
public put<T>(resource: string, model: any): Observable<T> {
const url = this.PrepareUrl(resource);
return this.http.put<T>(url, model).pipe(
retry(2),
catchError(this.catchBadResponse)
);
}
public delete(resource: string, id: any): Observable<any> {
const url = this.PrepareUrl(resource) + `\\${id}`;
return this.http.delete(url).pipe(
retry(2),
catchError(this.catchBadResponse)
);
}
protected PrepareUrl(resource: string): string {
return `${this.baseUrl}/${resource}`;
}
protected catchBadResponse(error: HttpErrorResponse) {
console.log('error occured!');
return throwError(error);
}
}
In addition, there is another class that extends the RestService class:
export class PersonRestService extends RestService {
constructor(protected http: HttpClient) {
super(http);
}
public get<T>(params?: HttpParams): Observable<T> {
return super.get<T>('person', params);
}
public post<T>(model: any): Observable<T> {
return super.post('person', model);
}
}
I am looking to override some functions in the child class, however, my IDE shows an error message:
Property 'get' in type 'PersonRestService' is not assignable to the same property in base type 'RestService'. Type '(params?: HttpParams) => Observable' is not assignable to type '(resource: string, params?: HttpParams) => Observable'. Types of parameters 'params' and 'resource' are incompatible. Type 'string' is not assignable to type 'HttpParams'.ts(2416)
What steps should I take to resolve this issue?