Skip to content

TypeScript: migrate deprecated package to TS #70362

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 7 commits into from
Jun 18, 2025

Conversation

USERSATOSHI
Copy link
Contributor

What?

Part of #67691
Migrating the deprecated package to Typescript.

Why?

To enhance DX and add type safety

How?

By porting the code to TypeScript

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

Copy link

github-actions bot commented Jun 9, 2025

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @USERSATOSHI! 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.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 9, 2025
@USERSATOSHI USERSATOSHI marked this pull request as ready for review June 9, 2025 09:34
Copy link

github-actions bot commented Jun 9, 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: USERSATOSHI <tusharbharti@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] Deprecated packages/deprecated labels Jun 9, 2025
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.

Thank you for your contribution.

This looks good, I just have a minor suggestion about the type improvements.

Comment on lines 10 to 12
* @type {Record<string, true | undefined>}
*/
export const logged = Object.create( null );
export const logged: Record< string, true | undefined > = Object.create( null );
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the undefined type here as the value is always true down there. So let us fix it

So, it should be

* @type {Record<string, true>}

and

Record< string, true >

Copy link
Member

Choose a reason for hiding this comment

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

In fact, let us remove that @type annonotation from the comment as the TS type is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, let us remove that @type annonotation from the comment as the TS type is sufficient.

Got it, I will remove the @type annonotations.
Do I also remove types from JSDoc and convert them to follow TSDoc or leave it like that?
like:

 * @param {string} feature               Name of the deprecated feature.
 * @param {Object} [options]             Personalisation options
 * @param {string} [options.since]       Version in which the feature was deprecated.
 * @param {string} [options.version]     Version in which the feature will be removed.
 * @param {string} [options.alternative] Feature to use instead
 * @param {string} [options.plugin]      Plugin name if it's a plugin feature
 * @param {string} [options.link]        Link to documentation
 * @param {string} [options.hint]        Additional message to help transition away from the deprecated feature.

to

 * @param feature               Name of the deprecated feature.
 * @param [options]             Personalisation options
 * @param [options.since]       Version in which the feature was deprecated.
 * @param [options.version]     Version in which the feature will be removed.
 * @param [options.alternative] Feature to use instead
 * @param [options.plugin]      Plugin name if it's a plugin feature
 * @param [options.link]        Link to documentation
 * @param [options.hint]        Additional message to help transition away from the deprecated feature.

cc: @manzoorwanijk

Copy link
Member

Choose a reason for hiding this comment

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

Let us move those docs to the type instead. So, it will be

type DeprecatedOptions = {
	/**
	 * Version in which the feature was deprecated.
	 */
	since?: string;
	// Other properties
};

and then change the options param like this

/**
 * @param {DeprecatedOptions} [options] Personalisation options
 */

Likewise for doAction docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, updating to this.

@USERSATOSHI
Copy link
Contributor Author

Updated the params and README.md to reflect the same.

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 perfect now. Congratulations for your first contribution 🎉

@manzoorwanijk manzoorwanijk enabled auto-merge (squash) June 17, 2025 10:49
@USERSATOSHI
Copy link
Contributor Author

Thank you very much :)

@manzoorwanijk manzoorwanijk merged commit 76223e7 into WordPress:trunk Jun 18, 2025
59 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.1 milestone Jun 18, 2025
@t-hamano t-hamano mentioned this pull request Jun 24, 2025
26 tasks
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
* refactor: migrate deprecated package from js to ts for type safety

* docs: move inline param docs to type definition

* docs: add the missing message param inline comment

* docs: fix param documentation for deprecated action
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] Deprecated packages/deprecated [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