RichText: useAnchor: Enable type checking, fix errors#75910
Conversation
|
Size Change: +53 B (0%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
e4af9c7 to
2a832f5
Compare
| settings, | ||
| }: { | ||
| editableContentElement: HTMLElement | null; | ||
| settings?: WPFormat; |
There was a problem hiding this comment.
Was there a use case for making settings optional? I'm keeping it that way for compat, but I don't see why it should be optional.
There was a problem hiding this comment.
It's optional for autocompleters. A single case in core, but it's better to keep it for compat.
gutenberg/packages/components/src/autocomplete/autocompleter-ui.tsx
Lines 99 to 101 in 83a8f44
|
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. |
There was a problem hiding this comment.
Pull request overview
This pull request converts the use-anchor.ts file from JavaScript to TypeScript, enabling proper type checking to prevent bugs like the one fixed in #75900 (a TypeError when autocomplete popovers appeared at the end of block lines).
Changes:
- Converted JSDoc type annotations to TypeScript type annotations throughout the file
- Added runtime type checks for type narrowing (instanceof checks)
- Implemented defensive null/undefined checks for edge cases
- Added proper handling for the non-standard
isActiveproperty that gets added to settings at runtime
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/rich-text/src/hook/use-anchor.ts | Converted from JSDoc to TypeScript, added type annotations, runtime type guards, and defensive null checks |
| packages/rich-text/README.md | Auto-generated documentation updates reflecting the TypeScript type signatures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Made redundant by the `! element.parentElement` check in the previous block. Now verified by the type checker.
|
@ciampo: 👍❓ |
|
Flaky tests detected in dd47efa. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22571588730
|
|
Thanks, @Mamaduka! |
* RichText: useAnchor: Enable type checking, fix errors Follow-up of #75900 * Convert to .ts * useAnchor: keep function signature tidy * Remove now-obsolete early return Made redundant by the `! element.parentElement` check in the previous block. Now verified by the type checker. Co-authored-by: mcsf <mcsf@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Follow-up of #75900
To do:
.tsWhy?
#75900 fixed a bug (#75897) that would have been caught by standard type checking, were it enabled. We should in general strive to have a lot more type checking going on.
How?
Check commit history for easier reviewing
Testing Instructions