TypeScript: Migrate format-library package to TS - #79486
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request migrates the @wordpress/format-library package source to TypeScript/TSX and updates @wordpress/rich-text typing/exports to support the migration, as part of the broader TypeScript conversion effort tracked in #67691.
Changes:
- Add TypeScript project configuration and project references for
packages/format-library. - Convert format implementations in
format-libraryto TS/TSX with explicit prop/value typing and safer interop typings. - Expand and re-export
RichTextFormattyping from@wordpress/rich-text, plus related documentation updates.
Reviewed changes
Copilot reviewed 26 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Adds packages/format-library to TS project references. |
| packages/rich-text/src/types.ts | Extends RichTextFormat shape (title/attributes/innerHTML) for TS consumers. |
| packages/rich-text/src/register-format-type.js | Updates typedef docs to reflect TS-friendly format settings shape. |
| packages/rich-text/src/index.ts | Re-exports RichTextFormat from ./types. |
| packages/rich-text/README.md | Adds a section documenting RichTextFormat. |
| packages/format-library/tsconfig.json | Introduces TS config + references for the format-library workspace. |
| packages/format-library/src/index.tsx | Adds a TS entrypoint to register default formats. |
| packages/format-library/src/default-formats.tsx | Centralizes the list of exported default formats. |
| packages/format-library/src/types.ts | Adds shared TS prop types for multiple format edit UIs. |
| packages/format-library/src/lock-unlock.ts | Adds a typed wrapper for private-apis lock/unlock usage. |
| packages/format-library/src/bold/index.tsx | Converts bold format implementation to TSX and typed props. |
| packages/format-library/src/italic/index.tsx | Converts italic format implementation to TSX and typed props. |
| packages/format-library/src/code/index.tsx | Converts code format implementation to TSX and types the input rule/edit props. |
| packages/format-library/src/underline/index.tsx | Converts underline edit props to typed TSX. |
| packages/format-library/src/strikethrough/index.tsx | Converts strikethrough edit props and toolbar button usage to TSX. |
| packages/format-library/src/subscript/index.tsx | Converts subscript edit props and toolbar button usage to TSX. |
| packages/format-library/src/superscript/index.tsx | Converts superscript edit props and toolbar button usage to TSX. |
| packages/format-library/src/keyboard/index.tsx | Converts keyboard format edit props to typed TSX. |
| packages/format-library/src/non-breaking-space/index.tsx | Adds explicit TS props for non-breaking-space edit. |
| packages/format-library/src/unknown/index.tsx | Adds RichTextValue typing and TS interop for toolbar button component typing. |
| packages/format-library/src/language/index.tsx | Converts language format to TSX with typed props and anchor typing. |
| packages/format-library/src/math/index.tsx | Converts math format UI to TSX with typed props/state. |
| packages/format-library/src/image/index.tsx | Converts inline image format UI to TSX with typed attributes/selection handling. |
| packages/format-library/src/text-color/index.tsx | Converts text-color format UI to TSX with typed props and safer DOM access. |
| packages/format-library/src/text-color/inline.tsx | Converts InlineColorUI helpers/components to TSX with explicit color/value typing. |
| packages/format-library/src/link/index.tsx | Converts link format edit UI to TSX with typed state and event handling. |
| packages/format-library/src/link/inline.tsx | Converts inline link UI to TSX with typed link value + safer rich-text operations typing. |
| packages/format-library/src/link/utils.ts | Adds TS types for link utilities (href validation, link format creation, boundary helpers). |
| packages/format-library/src/link/use-link-instance-key.ts | Types the link instance key helper hook. |
| packages/format-library/src/link/css-classes-setting.tsx | Types CSS classes setting component props and sanitization handler. |
Comments suppressed due to low confidence (3)
packages/rich-text/src/types.ts:11
RichTextFormatincludes the literal'core/link 'with a trailing space, which is easy to miss and will cause inconsistent type matching if| stringis ever narrowed later.
innerHTML?: string;
type:
| 'core/bold'
| 'core/italic'
| 'core/link '
packages/format-library/src/math/index.tsx:48
EditPropsis declared twice in this file, which will fail TypeScript compilation due to a duplicate identifier.
packages/format-library/src/link/utils.ts:168- The JSDoc still describes
formatas a string identifier, but the function now expects a format object with atypefield; please update the doc to match the actual parameter type.
cc81a16 to
36eb047
Compare
|
Let us first make the CI happy before we can review this. |
|
@manzoorwanijk , CI is now happy 😂 , Please help me with the review! Over to you! TIA 🙇 |
|
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. |
|
I think you've hit your monthly quota, so I'll take care of it for you. |
manzoorwanijk
left a comment
There was a problem hiding this comment.
Looking at this makes me realize that we should first convert the dependency packages like block-editor to avoid too many suppressions and use of any.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 31 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/format-library/src/link/inline.tsx:220
splitValue ?? []allowsvalAfterto becomeundefined, butreplace(valAfter, …)will then throw at runtime; either assertsplitalways returns a tuple here or handle theundefinedcase explicitly.
|
Checked out locally on a clean install: The migration is broadly sound. Three things outside the diff, plus one regression and a set of unnecessary casts inline. Not visible in the diff:
One regression: Runtime changes that aren't type-driven: Casts: most of the One process question: the five |
|
Hey 👋 I wanted to give you a heads-up since this pull request removes or renames files that have an ESLint suppression on #80123 enables an ESLint rule that requires that files containing JSX must use the What you'll need to do: You'll need to merge or rebase against the latest This comment is automated, based on pull requests with recent activity that contain affected |
…rmatOptions has correct comments
…SClassesSettingComponent
|
Hi @manzoorwanijk, Apologies for the delay in addressing the feedback. When you get a moment, please have a look at this PR and let me know if anything else is needed to move it forward. |
manzoorwanijk
left a comment
There was a problem hiding this comment.
This is in much better shape now. Thank you for the clean up of any.
Two things left that I'd like to settle before this lands, both inline:
- The new
elsebranch inonChangeLinkreplaces against the full value, which silently reintroduces the incorrectly-targeted-replacement bug (#41771) that the split was added to avoid. - The
titleadded toapplyFormatincode's__unstableInputRuleis inert, since onlytoggleFormatannounces, so that behaviour-changes bullet should say "Bold and italic".
The rest are nits and won't block.
|
Hi @manzoorwanijk, I really appreciate your quick feedback on this PR. I’m confident we’re close to the finish line with this issue. Please check it once again, and as always, let me know if there’s anything that needs to be fixed. |
manzoorwanijk
left a comment
There was a problem hiding this comment.
Thank you for your hard work. This looks great.
Let us fix the PR description before merge
Two bullets under "Behaviour changes" no longer match the code:
- "Bold, italic and code now announce apply/remove to screen readers".
codereverted; only bold and italic changed. - "Link: editing a link with no selection no longer throws; it replaces in place". It now bails out instead.
|
Wrong descriptions can sometimes mislead AI agents in future. |
|
Description fixed, thanks! Merging this. |
What?
Part of: #67691
Migrating the format-library package to Typescript.
Why?
Type safety.
Behaviour changes
Typing surfaced a few latent issues. These are behaviour changes, not typing:
undefined, before validation.Notes on review feedback
replace()accepted a value object at runtime but declared{Function|string}; corrected inrich-text.block-editortsconfig reference stays —validate-tsconfigrequires one per@wordpress/*dependency.