-
Notifications
You must be signed in to change notification settings - Fork 4.5k
TypeScript: migrate priority-queue package to TS #70469
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
TypeScript: migrate priority-queue package to TS #70469
Conversation
👋 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. |
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/priority-queue/src/index.ts
Outdated
*/ | ||
export type WPPriorityQueueCallback = () => void; |
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.
We can simply use
export type WPPriorityQueueCallback = () => void; | |
export type WPPriorityQueueCallback = VoidFunction; |
packages/priority-queue/src/index.ts
Outdated
/** | ||
* Reset the entire queue, clearing pending callbacks. | ||
*/ | ||
reset: () => void; |
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.
reset: () => void; | |
reset: VoidFunction; |
/** | ||
* @param timeOrDeadline - IdleDeadline object or a timestamp number. | ||
*/ | ||
export type RequestIdleCallbackCallback = ( | ||
timeOrDeadline: IdleDeadline | number | ||
) => void; |
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.
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(); |
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.
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;
};
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 now. Thanks
Co-authored-by: kushagra-goyal-14 <kush123@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
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.