Skip to content

tsgo: Fix type errors in forms, shared-extension-utils, woocommerce-analytics, and jetpack - #47423

Merged
manzoorwanijk merged 5 commits into
trunkfrom
update/tsgo/fix-type-errors-in-multiple-packages
Mar 3, 2026
Merged

manzoorwanijk merged 5 commits into
trunkfrom
update/tsgo/fix-type-errors-in-multiple-packages

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Member

Completes MONOREP-383, MONOREP-384, MONOREP-385

Proposed changes:

  • js-packages/shared-extension-utils: Add @typedef for ModuleStatus return type; add @deprecated to getJetpackData().
  • packages/forms: Tighten JSDoc @return/@typedef tags; patch @wordpress/interactivity@6.40.0 to fix incomplete Window.scheduler type (upstream fix: Interactivity: Fix incomplete Window.scheduler type causing TS2430 in downstream projects WordPress/gutenberg#76070).
  • packages/woocommerce-analytics: Change randomBytes type to Uint8Array<ArrayBuffer> to match crypto.getRandomValues return type.
  • plugins/jetpack (AI Assistant block): Replace deprecated getJetpackData()?.adminUrl with getMyJetpackUrl() from @automattic/jetpack-script-data.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Run pnpm typecheck
  • All should exit cleanly with no errors.

Changelog

  • Generate changelog entries for this PR (using AI).

@manzoorwanijk
manzoorwanijk requested review from a team March 3, 2026 08:34
@manzoorwanijk manzoorwanijk self-assigned this Mar 3, 2026
Copilot AI review requested due to automatic review settings March 3, 2026 08:34
@manzoorwanijk manzoorwanijk added [Status] Needs Review This PR is ready for review. Code Quality labels Mar 3, 2026
@github-actions

github-actions Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/tsgo/fix-type-errors-in-multiple-packages branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/tsgo/fix-type-errors-in-multiple-packages
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/tsgo/fix-type-errors-in-multiple-packages

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 deprecated getJetpackData()?.adminUrl composition.
  • Tighten/clarify JSDoc types (@typedef, @return) in Forms and shared-extension-utils; deprecate getJetpackData().
  • Add a pnpm patched dependency for @wordpress/interactivity@6.40.0 to adjust Window.scheduler typings; 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

  • randomBytes is never initialized when window.crypto.getRandomValues is unavailable, but it’s still written to in the fallback loop (randomBytes[i] = ...). This will throw at runtime on environments without crypto (and TS can’t catch it here). Initialize randomBytes in the else branch (e.g., allocate a Uint8Array(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.

Comment thread .pnpm-patches/@wordpress__interactivity@6.40.0.patch
Comment thread .pnpm-patches/@wordpress__interactivity@6.40.0.patch
Comment thread projects/js-packages/shared-extension-utils/src/get-jetpack-data.js Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 3, 2026 08:53
@jp-launch-control

jp-launch-control Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

This 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. 🤷

Full summary · PHP report · JS report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, randomBytes is never initialized before assigning randomBytes[i], which would throw at runtime if that branch is reached. Consider initializing randomBytes (e.g., allocate the Uint8Array up front) before the if so 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.

@simison simison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forms 👍

@manzoorwanijk
manzoorwanijk merged commit 1fc9cd6 into trunk Mar 3, 2026
97 checks passed
@manzoorwanijk
manzoorwanijk deleted the update/tsgo/fix-type-errors-in-multiple-packages branch March 3, 2026 09:40
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants