Skip to content

Conversation

kushagra-goyal-14
Copy link
Contributor

What?

Part of #67691

Migrating the priority-queue package to TypeScript.

Why?

To enhance DX and add type safety.

How?

By porting the code and tests to TypeScript.

Testing Instructions

Typecheck and unit tests.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 18, 2025
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @kushagra-goyal-14! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@kushagra-goyal-14 kushagra-goyal-14 marked this pull request as ready for review June 18, 2025 10:25
Copy link

github-actions bot commented Jun 18, 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: kushagra-goyal-14 <kush123@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] Priority Queue /packages/priority-queue labels Jun 20, 2025
@t-hamano t-hamano mentioned this pull request Jun 24, 2025
39 tasks
*/
export type WPPriorityQueueCallback = () => void;
Copy link
Member

Choose a reason for hiding this comment

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

We can simply use

Suggested change
export type WPPriorityQueueCallback = () => void;
export type WPPriorityQueueCallback = VoidFunction;

/**
* Reset the entire queue, clearing pending callbacks.
*/
reset: () => void;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
reset: () => void;
reset: VoidFunction;

Comment on lines 6 to 11
/**
* @param timeOrDeadline - IdleDeadline object or a timestamp number.
*/
export type RequestIdleCallbackCallback = (
timeOrDeadline: IdleDeadline | number
) => void;
Copy link
Member

Choose a reason for hiding this comment

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

The jsdoc for the param is better inline

export type RequestIdleCallbackCallback = (
	/**
	 * @param timeOrDeadline - IdleDeadline object or a timestamp number.
	 */
	timeOrDeadline: IdleDeadline | number
) => void;

Also, if we move that type to a types.ts file and import here, we can preserver the git history for this file.

@@ -29,7 +29,7 @@ describe( 'createQueue', () => {
queue.add( {}, callback );

expect( callback ).not.toHaveBeenCalled();
requestIdleCallback.tick();
( requestIdleCallback as any ).tick();
Copy link
Member

Choose a reason for hiding this comment

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

If you replace its import at the top with this, then you will not need to assert as any

import _requestIdleCallback from '../request-idle-callback';

const requestIdleCallback =
	_requestIdleCallback as typeof _requestIdleCallback & {
		tick: ( deadline?: Partial< IdleDeadline > | number ) => void;
	};

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 now. Thanks

@manzoorwanijk manzoorwanijk enabled auto-merge (squash) July 24, 2025 09:31
@manzoorwanijk manzoorwanijk merged commit ccfbe73 into WordPress:trunk Jul 24, 2025
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Jul 24, 2025
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Jul 31, 2025
Co-authored-by: kushagra-goyal-14 <kush123@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Priority Queue /packages/priority-queue [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