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.

HttpParams get and getAll methods return type does not support number neither boolean

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Jun 24, 2021

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.

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

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 >

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