Skip to content

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

@aanaya-deltacom

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: common/httpIssues related to HTTP and HTTP Client

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions