Add some typing to block-editor utils#76885
Add some typing to block-editor utils#76885wwahammy wants to merge 3 commits intoWordPress:trunkfrom
Conversation
There was a problem hiding this comment.
I found copies of the first two functions in the global-styles-engine so I figured I'd just switch this to typescript like that file and migrate the contents over.
| let plainText = ''; | ||
| let html = ''; | ||
|
|
||
| if ( ! clipboardData ) { |
There was a problem hiding this comment.
This is slightly redundant as the try block would catch when clipboardData is null. Unfortunately, Typescript doesn't realize that so it doesn't know that clipboardData is non-null in the rest of the method. This works around that limitation.
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
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. |
What?
This continues the effort of typing more of the @wordpress/block-editor package. I worked on two particular files in the src/utils subfolder: object.js and pasting.js
Why?
Potentially improve code quality with more typing in @wordpress/block-editor. Additionally the tsconfig.json for the package says the package is being slowly typed so I figured I'd help 😄
How?
I noticed that the src/utils/object.js file is mostly the same as similar utils file in the global-styles-engine. Given that I figured I'd migrate the file straight to ts so I can reuse the code.
Typing the src/utils/pasting.js file required two small changes to the getPasteEventData function:
Testing Instructions
Likely none required, only one functional change, a redundant null check.
Use of AI Tools
None.