fix(common): make types for HttpClient more readable by crisbeto · Pull Request #59901 · angular/angular · GitHub
Skip to content

fix(common): make types for HttpClient more readable - #59901

Closed
crisbeto wants to merge 1 commit into
angular:mainfrom
crisbeto:simplify-http-client-types
Closed

crisbeto wants to merge 1 commit into
angular:mainfrom
crisbeto:simplify-http-client-types

Conversation

@crisbeto

@crisbeto crisbeto commented Feb 10, 2025 •

Copy link
Copy Markdown
Member

HttpClient has a lot of overloads to achieve proper type checking, however each overload is also very long which makes it hard to read on adev. These changes replace the object literal types with Record to make them a bit more concise.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release adev: preview labels Feb 10, 2025
@angular-robot angular-robot Bot added the area: common Issues related to APIs in the @angular/common package label Feb 10, 2025
@ngbot ngbot Bot added this to the Backlog milestone Feb 10, 2025
@crisbeto
crisbeto force-pushed the simplify-http-client-types branch from b122106 to e68dd76 Compare February 10, 2025 08:05
@github-actions

github-actions Bot commented Feb 10, 2025 •

Copy link
Copy Markdown

@crisbeto

Copy link
Copy Markdown
Member Author

`HttpClient` has a lot of overloads to achieve proper type checking, however each overload is also very long which makes it hard to read on adev. These changes replace the object literal types with `Record` to make them a bit more concise.
@crisbeto
crisbeto force-pushed the simplify-http-client-types branch from e68dd76 to a5fc4a2 Compare February 10, 2025 08:19
@crisbeto
crisbeto marked this pull request as ready for review February 10, 2025 08:45
@rubiesonthesky

rubiesonthesky commented Feb 10, 2025 •

Copy link
Copy Markdown

Could there be exported type for the param value string | number | boolean | ReadonlyArray<string | number | boolean> or params object Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>? Those are used multiple times in the file. I'd like to also be able to use that type in my projects easily :)

For consistency, HttpParamsOptions.fromObject could be changed to use Record.

@crisbeto

Copy link
Copy Markdown
Member Author

@rubiesonthesky that's actually what I had in the first version of this PR. I ended up reverting it, because it didn't make much of a difference in the display type on angular.dev. There seems to be some logic that truncates long types.

@wartab

wartab commented Feb 10, 2025

Copy link
Copy Markdown
Contributor

Don't take me seriously, but

let a: {[k:string]: string} = {}; // 33 chars
let b: Record<string, string> = {}; // 35 chars
let c: {[key:string]: string} = {}; // 35 chars

@AndrewKushnir
AndrewKushnir requested review from alxhub and removed request for AndrewKushnir February 10, 2025 17:41

@pkozlowski-opensource pkozlowski-opensource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: fw-general
Reviewed-for: public-api

@pullapprove
pullapprove Bot requested a review from kirjs February 25, 2025 14:37

@kirjs kirjs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: fw-general
Reviewed-for: public-api

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 25, 2025
@kirjs

kirjs commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 07338c0.

The changes were merged into the following branches: main, 19.1.x, 19.2.x

kirjs pushed a commit that referenced this pull request Feb 25, 2025
`HttpClient` has a lot of overloads to achieve proper type checking, however each overload is also very long which makes it hard to read on adev. These changes replace the object literal types with `Record` to make them a bit more concise.

PR Close #59901
kirjs pushed a commit that referenced this pull request Feb 25, 2025
`HttpClient` has a lot of overloads to achieve proper type checking, however each overload is also very long which makes it hard to read on adev. These changes replace the object literal types with `Record` to make them a bit more concise.

PR Close #59901
@kirjs kirjs closed this in 07338c0 Feb 25, 2025
@angular-automatic-lock-bot

Copy link
Copy Markdown

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Mar 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker adev: preview area: common Issues related to APIs in the @angular/common package target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants