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.

HttpClient should support hybrid type options

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  
[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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
artuskacommented, Dec 29, 2017

This does work with the http:

let config = {
    params: params,
    observe: 'response'
};

let request = this.http.get(path, config);

This does not work with the httpClient:

let config = {
    params: params,
    observe: 'response'
};

let request = this.httpClient.get(path, config);

Because httpClient is stricted to observe?: "body".

Just saying.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 25, 2021

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

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 >

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