Skip to content

HttpParams instantiation using fromObject option with number or boolean parameters does not convert them to string #42641

Closed

Description

@aanaya-deltacom

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 #40663

When a new HttpParams object is created using that option, then the parameters are not converted to string, so when using the get and getAll methods the value does not match the expected string | null type.

This causes type errors and tests failing.

Check this comment for more info about the fix: #42637 (comment)

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

Activity

  1. petebacondarwin commented on Jun 24, 2021

    @petebacondarwin
    Contributor

    @cexbrayat - do you want to take this one?

  2. added
    area: common/http
    P3
    on Jun 24, 2021
  3. modified the milestone: Backlog on Jun 24, 2021
  4. cexbrayat commented on Jun 24, 2021

    @cexbrayat
    Member

    Sure, I'll take a look

  5. added a commit that references this issue on May 2, 2022
    1c311a0
  6. angular-automatic-lock-bot commented on Jun 4, 2022

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: common/http

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions