Имплементация на гите
Мой метод:
public get<T>(url: string, options: HttpClientOptionsModel = {}) {
return this.http.get<T>(`${environment.server_url}/${url}`, options);
}
Мой интерфейс:
import {HttpContext, HttpHeaders, HttpParams} from "@angular/common/http";
export interface HttpClientOptionsModel {
headers?: HttpHeaders | { [header: string]: string | string[] },
context?: HttpContext,
observe?: 'body'|'events'|'response',
params?: HttpParams | { [param: string]: string | number | boolean | ReadonlyArray<string|number|boolean> },
reportProgress?: boolean,
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text',
withCredentials?: boolean,
}
ОшибкаTS2769: No overload matches this call. Overload 1 of 15, '(url: string, options: { headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; observe: "events"; context?: HttpContext | undefined; params?: HttpParams | ... 1 more ... | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; }): Observable<...>', gave the following error. Argument of type 'HttpClientOptionsModel' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; observe: "events"; context?: HttpContext | undefined; params?: HttpParams | { ...; } | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; }'. Types of property 'observe' are incompatible. Type '"events" | "body" | "response" | undefined' is not assignable to type '"events"'. Type 'undefined' is not assignable to type '"events"'. Overload 2 of 15, '(url: string, options: { headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; observe: "response"; context?: HttpContext | undefined; params?: HttpParams | ... 1 more ... | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; }): Observable<...>', gave the following error. Argument of type 'HttpClientOptionsModel' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; observe: "response"; context?: HttpContext | undefined; params?: HttpParams | { ...; } | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; }'. Types of property 'observe' are incompatible. Type '"events" | "body" | "response" | undefined' is not assignable to type '"response"'. Type 'undefined' is not assignable to type '"response"'. Overload 3 of 15, '(url: string, options?: { headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; context?: HttpContext | undefined; observe?: "body" | undefined; params?: HttpParams | ... 1 more ... | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; } | undefined): Observable<...>', gave the following error. Argument of type 'HttpClientOptionsModel' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; } | undefined; context?: HttpContext | undefined; observe?: "body" | undefined; params?: HttpParams | { ...; } | undefined; reportProgress?: boolean | undefined; responseType?: "json" | undefined; withCredentials?: boolean | undefined; }'. Types of property 'observe' are incompatible. Type '"events" | "body" | "response" | undefined' is not assignable to type '"body" | undefined'. Type '"events"' is not assignable to type '"body"'.
Как написано
здесь as any
отключает проверку типов, таким образом
options as any
фиксит проблему, однако верно ли это решение?