Not work spread when I set options to HttpClient.get after migrate to v.6
See original GitHub issueI’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:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 typeany
, then the result of the spread operation{...options, observe: 'response'}
actually has typeany
as well.any
is pretty infectious in TypeScript. This means that TS will just take the first signature ofget
(becauseany
matches anything!) which happens to return anObservable<ArrayBuffer>
.What you should do is type the
options
parameter to your function more aggressively - I always try to avoidany
where possible in my TS code. If you give this parameter a correct type, your spread operation will work as expected.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.