我已经用http方法的描述创建了RestService。当我尝试将HttpParams传递给此方法以及创建新的HttpRequest时,我遇到了问题。
下面的方法。问题出在params?: URLSearchParams | HttpParams | { [key: string]: any | any[] } | null
post<T>(
relativeUrl: string,
body?: any,
params?: URLSearchParams | HttpParams | { [key: string]: any | any[] } | null,
headers?: HttpHeaders | null,
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text' | null): Observable<HttpResponse<T>> {
return this.executeRequest(this.createRequest(relativeUrl, body, params, headers, responseType, RequestMethod.POST));
}
在方法createRequest
中,我编写了以下代码
let init = {
headers: headers,
params: params,
responseType: responseType
};
return new HttpRequest(method, url, body, init);
但是init被报告为错误
错误TS2345:类型为'{headers的参数:HttpHeaders;参数:URLSearchParams | HttpParams | {[key:string]:any; };无法将responseT ...'分配给类型'{headers ?: HttpHeaders; reportProgress ?:布尔值; params ?: HttpParams; responseType ?:“文本” | “ ...”。
怎么了?