Repository navigation
tsgo: Fix type errors in forms, shared-extension-utils, woocommerce-analytics, and jetpack - #47423
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
There was a problem hiding this comment.
Pull request overview
This PR addresses TypeScript (tsgo) type errors across several packages in the monorepo, including Jetpack, Forms, WooCommerce Analytics, and shared extension utilities, and adds a pnpm patch for a WordPress dependency type issue.
Changes:
- Update Jetpack AI Assistant to use
getMyJetpackUrl()instead of deprecatedgetJetpackData()?.adminUrlcomposition. - Tighten/clarify JSDoc types (
@typedef,@return) in Forms and shared-extension-utils; deprecategetJetpackData(). - Add a pnpm patched dependency for
@wordpress/interactivity@6.40.0to adjustWindow.schedulertypings; update lockfile accordingly.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/plugins/jetpack/extensions/blocks/ai-assistant/hooks/use-ai-product-page/index.ts | Switches My Jetpack URL generation to getMyJetpackUrl() |
| projects/plugins/jetpack/changelog/update-tsgo-fix-type-errors-in-multiple-packages | Jetpack changelog entry for TS type fixes |
| projects/packages/woocommerce-analytics/src/client/utils.ts | Adjusts randomBytes typing in generateRandomToken() |
| projects/packages/woocommerce-analytics/changelog/update-tsgo-fix-type-errors-in-multiple-packages | WooCommerce Analytics changelog entry |
| projects/packages/forms/src/store/form-step-preview.js | Adds StepInfo typedef and tightens selector return type |
| projects/packages/forms/src/blocks/shared/hooks/use-find-block-recursively.js | Adds Block typedef and tightens hook return type |
| projects/packages/forms/src/blocks/contact-form/components/jetpack-integration-controls.js | Tightens return type to ReactNode |
| projects/packages/forms/changelog/update-tsgo-fix-type-errors-in-multiple-packages | Forms changelog entry |
| projects/js-packages/shared-extension-utils/src/hooks/use-module-status/index.js | Adds ModuleStatus typedef for hook return type |
| projects/js-packages/shared-extension-utils/src/get-jetpack-data.js | Marks getJetpackData() deprecated |
| projects/js-packages/shared-extension-utils/changelog/update-tsgo-fix-type-errors-in-multiple-packages | shared-extension-utils changelog entry |
| pnpm-workspace.yaml | Adds patched dependency entry for @wordpress/interactivity@6.40.0 |
| pnpm-lock.yaml | Records the patch hash/path for the patched dependency |
| .pnpm-patches/@wordpress__interactivity@6.40.0.patch | Patch modifying Window.scheduler type shape in @wordpress/interactivity |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
projects/packages/woocommerce-analytics/src/client/utils.ts:31
randomBytesis never initialized whenwindow.crypto.getRandomValuesis unavailable, but it’s still written to in the fallback loop (randomBytes[i] = ...). This will throw at runtime on environments withoutcrypto(and TS can’t catch it here). InitializerandomBytesin theelsebranch (e.g., allocate aUint8Array(randomBytesLength)before the loop) or refactor the fallback to build an array and convert it before encoding.
let randomBytes: Uint8Array< ArrayBuffer >;
if ( window.crypto && window.crypto.getRandomValues ) {
randomBytes = new Uint8Array( randomBytesLength );
window.crypto.getRandomValues( randomBytes );
} else {
for ( let i = 0; i < randomBytesLength; ++i ) {
randomBytes[ i ] = Math.floor( Math.random() * 256 );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
projects/packages/woocommerce-analytics/src/client/utils.ts:31
- In the non-crypto fallback branch,
randomBytesis never initialized before assigningrandomBytes[i], which would throw at runtime if that branch is reached. Consider initializingrandomBytes(e.g., allocate theUint8Arrayup front) before theifso both branches write into a valid buffer.
export function generateRandomToken( randomBytesLength: number ): string {
let randomBytes: Uint8Array< ArrayBuffer >;
if ( window.crypto && window.crypto.getRandomValues ) {
randomBytes = new Uint8Array( randomBytesLength );
window.crypto.getRandomValues( randomBytes );
} else {
for ( let i = 0; i < randomBytesLength; ++i ) {
randomBytes[ i ] = Math.floor( Math.random() * 256 );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Completes MONOREP-383, MONOREP-384, MONOREP-385
Proposed changes:
js-packages/shared-extension-utils: Add@typedefforModuleStatusreturn type; add@deprecatedtogetJetpackData().packages/forms: Tighten JSDoc@return/@typedeftags; patch@wordpress/interactivity@6.40.0to fix incompleteWindow.schedulertype (upstream fix: Interactivity: Fix incompleteWindow.schedulertype causing TS2430 in downstream projects WordPress/gutenberg#76070).packages/woocommerce-analytics: ChangerandomBytestype toUint8Array<ArrayBuffer>to matchcrypto.getRandomValuesreturn type.plugins/jetpack(AI Assistant block): Replace deprecatedgetJetpackData()?.adminUrlwithgetMyJetpackUrl()from@automattic/jetpack-script-data.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
pnpm typecheckChangelog