HttpClient should support hybrid type options
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[x] 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
Current behavior
HttpClient methods don’t support options that are typed as, e.g. { observe: 'body' | 'events' }
observe
has the type HttpObserve
which is 'body' | 'events' | 'response'
, which is supposed to accept the above type.
The signature overloading seems to need to repeat the signature of the final definition.
Expected behavior
HttpClient methods work with options that are typed as, e.g. { observe: 'body' | 'events' }
Minimal reproduction of the problem with instructions
function f(x: string): string;
function f(x: number): number;
// function f(x: string | number): any;
function f(x: string | number): any {
return x;
}
interface X {
x: number | string;
}
function x(a: X) {
f(a.x); // this reports an error, needs line 3 to fix (which I think is absurd)
}
Argument of type 'string | number' is not assignable to parameter of type 'number'.
Type 'string' is not assignable to type 'number'.
What is the motivation / use case for changing the behavior?
I need more flexible typing in writing my app specific wrapper of HttpClient
.
Environment
Angular version: 4.3.2
EDIT
Looks like HttpClient.request
correctly repeats the final signature before the real implementation.
None of the other methods (get
, post
, etc) do the same. Must be missed out.
So my current workaround would be to use request
for all the things…
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cannot inject HttpClient in an AngularJS/Angular hybrid app ...
The service works fine without the reference to HttpClient. It is not a problem with the service as if I try to inject...
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 >The Hybrid Flow – Securing ASP.NET Core Web Application
In this part of the series, we are going to learn how to secure our web application (a client application) by using the...
Read more >Introducing AWS Common Runtime HTTP Client in the AWS ...
Option 1: Specify the CRT HTTP client through the client builder · Option 2: Remove other async HTTP clients from the classpath ·...
Read more >Call Your API Using the Hybrid Flow - Auth0
The Authorization Code will be available in the code URL parameter. You must specify this URL as a valid callback URL in your...
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 Free
Top 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
This does work with the
http
:This does not work with the
httpClient
:Because
httpClient
is stricted toobserve?: "body"
.Just saying.
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.