Skip to content

Converts RichText Package to Typescript#69314

Open
margolisj wants to merge 15 commits intoWordPress:trunkfrom
margolisj:feature/richtext-TS
Open

Converts RichText Package to Typescript#69314
margolisj wants to merge 15 commits intoWordPress:trunkfrom
margolisj:feature/richtext-TS

Conversation

@margolisj
Copy link
Contributor

@margolisj margolisj commented Feb 25, 2025

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
Copy link

github-actions bot commented Feb 25, 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: margolisj <[email protected]>
Co-authored-by: manzoorwanijk <[email protected]>

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
@margolisj margolisj mentioned this pull request Feb 25, 2025
40 tasks
@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
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
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.

replacements: Array< RichTextFormat >;
start: number;
end: number;
formats: Array< RichTextFormatList | undefined >;
Copy link
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
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
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
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
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
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
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.

3 participants