question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not work spread when I set options to HttpClient.get after migrate to v.6

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report 
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

I call my base function:

protected get(url: string, options?: any): Observable<HttpResponse<any>> {
    return this.http.get(url, {...options, observe: 'response'});
}

When http is HttpClient. I get error:

Type ‘Observable<ArrayBuffer>’ is not assignable to type ‘Observable<HttpResponse<any>>’.

I try change call of function, added <any>:

this.http.get<any>(url, {...options, observe: 'response'})

And get error:

Type ‘Observable<HttpEvent<any>>’ is not assignable to type ‘Observable<HttpResponse<any>>’.

Expected behavior

But, if I remove options and spread: this.http.get(url, {observe: 'response'}) It works as expected and in v.5 and latter…

Environment


Angular version: 6.1.8

Browser:
- [x] Chrome (desktop) version last
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.11.1
- Platform:  Windows

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alxhubcommented, Dec 14, 2018

This is some strange behavior, for sure!! It took me a moment to realize what was happening.

What’s actually happening is that because your options object has type any, then the result of the spread operation {...options, observe: 'response'} actually has type any as well. any is pretty infectious in TypeScript. This means that TS will just take the first signature of get (because any matches anything!) which happens to return an Observable<ArrayBuffer>.

What you should do is type the options parameter to your function more aggressively - I always try to avoid any where possible in my TS code. If you give this parameter a correct type, your spread operation will work as expected.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 14, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 4 HttpClient Query Parameters - Stack Overflow
I have been looking for a way to pass query parameters into an API call with the new HttpClientModule 's HttpClient and have...
Read more >
Communicating with backend services using HTTP - Angular
Before you can use HttpClient , you need to import the Angular ... this does NOT work const options = { responseType: 'text',...
Read more >
Creating and Using HTTP Client SDKs in .NET 6 - InfoQ
In this article, the author explains the process behind developing HTTP Client SDKs in .NET 6. The article also contains a sample SDK ......
Read more >
Should we create a new single instance of HttpClient for all ...
Short answer: use a static HttpClient. If you need to support DNS changes (of your web server or other servers), then you need...
Read more >
Upgrading a .NET 5 "Startup-based" app to .NET 6
Option 2: Re-use your Startup class. But what if you really want to use the new WebApplication -style, but don't want to put...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found