1
votes

I am using "@angular/common": "^6.0.7", and the documentation says that a httclient.request can either take in a string or HttpRequest. Yet when I pass in HttpRequest i get error TS2345: Argument of type 'HttpRequest<{ reportProgress: boolean; observe: string; }>' is not assignable to parameter of type 'string'.

Below is the code.

const req = new HttpRequest('GET', url, {
  reportProgress: true,
  observe: 'response'
});

return this.http.request(
  req, url, {
    observe: 'response'
  }).pipe(
  retry(3),
  catchError(this.handleError));

Thanks.

Solution

Look at the function used. In my case

 return this.http.request(
          req.pipe(
          retry(3),
          catchError(this.handleError));
1
what if you remove url from the return statement. return this.http.request(req, {observe: 'response'})...Jason White
now it gives Argument of type 'HttpRequest<{}>' is not assignable to parameter of type 'string'.Jones
There are 17 overloads of the request method. A single one of them (the first one listed in the documentation) takes an HttpRequest as argument, and it's the only argument of the method. But you're passing 3 arguments. The url and the options are already specified in the HttpRequest. Why woud you pass them a second time when calling the method?JB Nizet
Yes, you are right. it works now. Did not see that.Jones

1 Answers

0
votes

The documentation says you can pass the type HttpRequest. So when you construct it pass that.

  const req = new HttpRequest('GET', url, {
      reportProgress: true
    });

    return this.http.request(req).pipe(
     map(event => this.getEventMessage(event, file)),
      retry(3),
      catchError(this.handleError));