HttpParams get and getAll methods return type does not support number neither boolean
See original GitHub issueBug Report
Affected Package
The issue is caused by package @angular/common/http
Is this a regression?
No.
Description
From Angular version 12, the HttpParamsOptions
allows number
and boolean
types in fromObject
, introduced with commit https://github.com/angular/angular/pull/40663
But, the return type for get
and getAll
methods in HttpParams
is string | null
and string[] | null
respectively.
This causes type errors and tests failing.
Minimal Reproduction
const params = new HttpParams({ fromObject: { numericParam: 5 } });
console.log(
typeof params.get('numericParam') === 'number', // true
params.get('numericParam') === '5', // false
// params.get('numericParam') === 5, // does not compile
);
Your Environment
Angular Version:
Angular CLI: 12.0.3
Node: 14.15.4
Package Manager: npm 6.14.10
OS: linux x64
Angular: 12.0.4
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1200.3
@angular-devkit/build-angular 12.0.3
@angular-devkit/core 12.0.3
@angular-devkit/schematics 12.0.3
@angular/cli 12.0.3
@angular/flex-layout 12.0.0-beta.34
@schematics/angular 12.0.3
rxjs 6.6.7
typescript 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
URL Parameters, Query Parameters, httpparams in Angular ...
This post is a guide how to Pass the URL Parameters or Query string along with the HTTP Request using the HttpClient in...
Read more >How to pass an array within a query string in HttpClient?
I think the best way is to add them to parameters as a string and have your back-end convert it back to an...
Read more >HttpParams - Angular
Returns. boolean : True if the parameter has one or more values, false if it has no value or is not present. get()link...
Read more >HttpParams - Angular
This class is immutable - all mutation operations return a new instance. ... Get all values for the given parameter name, or null...
Read more >Communicating with backend services using HTTP - Angular
The asynchronous method sends an HTTP request, and returns an Observable that emits the requested data when the response is received. The return...
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
I don’t think this is actually a regression, since in v11 not only can you not pass a number into the HttpParamsOptions, the return type was also always string.
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.