类型'{标题的参数:HttpHeaders;参数:当我尝试传递参数时,http方法中的URLSearchParam ...

时间:2019-06-12 21:44:05

标签: angular parameters angular-httpclient

我已经用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 ?:“文本” | “ ...”。

怎么了?

0 个答案:

没有答案