Search code examples
javascripttypescriptjhipsterarraybuffer

Set HTTP responseType as arraybuffer


I facing an error while building a jhipster project that says that I need to change the parameter responseType in a get request.

Here's the error:

Argument of type '{ responseType: "arraybuffer"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'responseType' are incompatible. Type '"arraybuffer"' is not assignable to type '"json"'. Version: typescript 2.7.2

As you see typescript is telling me to change the value from arraybuffer to json, but I need to keep it as arraybuffer since I am dealing with a file and I fully aware that the responseType can be set to arraybuffer, blob, json or text.

Here's the code

showfile(file?: any): Observable<any> {
    return this.http.get<any>(SERVER_API_URL + `leave/api/downloadFile/${file}`, { responseType: 'arraybuffer' });
}

Solution

  • this.http.get<any>
    

    Remove the any