-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Migrate @packages/url
package to TypeScript
#70496
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@packages/url
package to TypeScript@packages/url
package to TypeScript
@packages/url
package to TypeScript@packages/url
package to TypeScript
There was a problem hiding this 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.
There was a problem hiding this 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', () => ( {
packages/url/src/add-query-args.ts
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
export function addQueryArgs( url: string = '', args?: Object ): string { | |
export function addQueryArgs( url: string = '', args?: Record<string, unknown> ): string { |
Copilot uses AI. Check for mistakes.
I agree with the Copilot suggestions though. |
6dfdf3c
to
ea8c83b
Compare
What?
Part of: #67691
Migrating the url package to Typescript.
Why?
Type safety.