Skip to content

Migrate @packages/url package to TypeScript #70496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 18, 2025

Conversation

im3dabasia
Copy link
Contributor

What?

Part of: #67691
Migrating the url package to Typescript.

Why?

Type safety.

Copy link

github-actions bot commented Jun 23, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: manzoorwanijk <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia marked this pull request as draft June 23, 2025 14:08
@im3dabasia im3dabasia changed the title Migrate @packages/url package to TypeScript [WIP]: Migrate @packages/url package to TypeScript Jun 23, 2025
@im3dabasia im3dabasia changed the title [WIP]: Migrate @packages/url package to TypeScript Migrate @packages/url package to TypeScript Jun 23, 2025
@im3dabasia im3dabasia marked this pull request as ready for review June 23, 2025 17:14
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] Url /packages/url labels Jun 24, 2025
@t-hamano t-hamano mentioned this pull request Jun 24, 2025
32 tasks
@manzoorwanijk manzoorwanijk requested a review from Copilot July 14, 2025 07:29
Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

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

This looks good. Thank you.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the @packages/url package from JavaScript to TypeScript by adding explicit type annotations, removing JSDoc type comments, and updating documentation.

  • Added TypeScript function signatures and return types across all URL utilities
  • Removed {type} annotations from JSDoc and cleaned up markdown docs
  • Updated Jest mocks in tests to use extensionless module paths

Reviewed Changes

Copilot reviewed 30 out of 31 changed files in this pull request and generated 3 comments.

File Description
packages/url/src/test/index.js Adjusted jest.doMock calls to import modules without .js extensions
packages/url/src/safe-decode-uri.ts Added TS types to safeDecodeURI signature and cleaned JSDoc
packages/url/src/add-query-args.ts Typed url and args parameters and return value
packages/url/README.md Updated markdown to reflect TS types in parameter lists
Comments suppressed due to low confidence (2)

packages/url/README.md:31

  • [nitpick] For consistency, wrap markdown parameter names in backticks (e.g. `_url_`) and ensure bullet markers align with the surrounding doc style.
-   _url_ `string`: URL to which arguments should be appended. If omitted, only the resulting querystring is returned.

packages/url/src/test/index.js:497

  • Ensure that Jest’s module resolution is configured to mock extensionless paths. If the production code still imports ../get-path.js, the mock may not be applied correctly.
		jest.doMock( '../get-path', () => ( {

@@ -21,7 +21,7 @@ import { getFragment } from './get-fragment';
*
* @return {string} URL with arguments applied.
*/
export function addQueryArgs( url = '', args ) {
export function addQueryArgs( url: string = '', args?: Object ): string {
Copy link
Preview

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

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

Avoid using the generic Object type for args. Consider a more precise type such as Record<string, unknown> or a dedicated interface to improve type safety.

Suggested change
export function addQueryArgs( url: string = '', args?: Object ): string {
export function addQueryArgs( url: string = '', args?: Record<string, unknown> ): string {

Copilot uses AI. Check for mistakes.

@manzoorwanijk
Copy link
Member

I agree with the Copilot suggestions though.

@im3dabasia im3dabasia force-pushed the try/migrate-url-typescript branch from 6dfdf3c to ea8c83b Compare July 17, 2025 17:05
@manzoorwanijk manzoorwanijk merged commit 443d8fa into WordPress:trunk Jul 18, 2025
59 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.3 milestone Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Url /packages/url [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants