Skip to content

Converts RichText Package to Typescript - #69314

Closed
margolisj wants to merge 15 commits into
WordPress:trunkfrom
margolisj:feature/richtext-TS
Closed

margolisj wants to merge 15 commits into
WordPress:trunkfrom
margolisj:feature/richtext-TS

Conversation

@margolisj

@margolisj margolisj commented Feb 25, 2025 •

Copy link
Copy Markdown
Contributor

What?

Migrating the RichText package to Typescript. I'm working with and there are features that are not documented in the current types. I figured I might as well do the whole thing if allowed.

Why?

Type safety.

How?

Testing Instructions

Typecheck and unit tests.

@margolisj
margolisj requested a review from ellatrix as a code owner February 25, 2025 18:31
@github-actions

github-actions Bot commented Feb 25, 2025 •

Copy link
Copy Markdown

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: margolisj <margolisj@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>

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

@margolisj margolisj changed the title Converts Richtext Package to Typescript Converts RichText Package to Typescript Feb 25, 2025
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] Rich text /packages/rich-text labels Feb 26, 2025
@margolisj

Copy link
Copy Markdown
Contributor Author

So I've tried to leave everything as 1 to 1 as humanly possible. Currently stuck at a few important type decisions. I'm going to add a review of where I'll need some opinion / guidance. I've also left TODO's in the code at places that are more gnarly.

end: number;
formats: Array< RichTextFormatList | undefined >;
replacements: Array< RichTextFormat | undefined >;
// TODO: Should these really be optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this should be optional based on getting deeper into this problem.

Comment thread packages/rich-text/src/types.ts Outdated
replacements: Array< RichTextFormat >;
start: number;
end: number;
formats: Array< RichTextFormatList | undefined >;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are formats undefined outside of just the test cases? Same with the replacements below.

*/
export function isFormatEqual( format1, format2 ) {
export function isFormatEqual(
format1: RichTextFormat | null,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could be undefined instead of null.

start,
end,
}: RichTextValue ): boolean | undefined {
}: {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if these types will pass when converting the components.

];
const result = split( deepFreeze( record ), 6, 6 );
// TODO: These were taking too many parameters
const result = split( deepFreeze( record ), 6 );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unsure about this parameter change.

return doc.body.firstChild;
}

// function createElement( HTML: string ): HTMLElement {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Possibly want to swap to creating HTMLElements. JSDoc values were HTMLElements iirc yet using createNode.

@manzoorwanijk

Copy link
Copy Markdown
Member

Can we please update this branch from trunk, so that we can review it?

@manzoorwanijk
manzoorwanijk self-requested a review January 11, 2026 09:39
@im3dabasia

Copy link
Copy Markdown
Contributor

This PR needs to be updated with the latest changes from trunk. @margolisj, could you please take care of it?

@margolisj

Copy link
Copy Markdown
Contributor Author

@im3dabasia @manzoorwanijk Are people taking merging TS in PRs to gutenberg seriously now? I will have to check with my current employee and go through the standard process for that so please let me know, and if this will actually get merged, I'll get approval and clean this up.

@manzoorwanijk

manzoorwanijk commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Are people taking merging TS in PRs to gutenberg seriously now? I will have to check with my current employee and go through the standard process for that so please let me know, and if this will actually get merged, I'll get approval and clean this up.

Let me be honest here. This PR got stale just because I didn't feel confident reviewing it alone without the people who work with the Rich Text package, because it's too big a change for a single PR.

Let us make sure this gets through. So, here is what we can do:

  • Break the PR into smaller ones
  • Convert the test files to TS in a separate PR
  • Convert only a few files in a single PR

Once ready, please ping me, and I would be happy to help ship it.

Some important feedback for those smaller PRs:

  • Let us not use the WP prefix in TS types.
  • Let us ensure that there is no runtime change during the conversion.

@manzoorwanijk

Copy link
Copy Markdown
Member

The package is now converted to TS via #84324, #84365 and #84378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Rich text /packages/rich-text [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants