TypeScript: migrate priority-queue package to TS#70469
TypeScript: migrate priority-queue package to TS#70469manzoorwanijk merged 5 commits intoWordPress:trunkfrom
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
| * | ||
| * @typedef {()=>void} WPPriorityQueueCallback | ||
| */ | ||
| export type WPPriorityQueueCallback = () => void; |
There was a problem hiding this comment.
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.
| 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.
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.
|
|
||
| expect( callback ).not.toHaveBeenCalled(); | ||
| requestIdleCallback.tick(); | ||
| ( requestIdleCallback as any ).tick(); |
There was a problem hiding this comment.
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;
};
manzoorwanijk
left a comment
There was a problem hiding this comment.
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.