Skip to content

tsgo: Fix js-packages/shared-extension-utils type errors#47382

Open
manzoorwanijk wants to merge 2 commits intotrunkfrom
update/tsgo/fix-shared-extension-utils-type-errors
Open

tsgo: Fix js-packages/shared-extension-utils type errors#47382
manzoorwanijk wants to merge 2 commits intotrunkfrom
update/tsgo/fix-shared-extension-utils-type-errors

Conversation

@manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Feb 27, 2026

Fixes https://linear.app/a8c/issue/MONOREP-378

Proposed changes:

  • Convert get-jetpack-extension-availability.js to TypeScript with typed return (ExtensionAvailability interface), fixing TS2339 errors in downstream packages (ai-client, jetpack AI assistant blocks).
  • Convert use-autosave-and-redirect/index.js to TypeScript with typed return (UseAutosaveAndRedirectReturn interface), fixing TS2339 errors in downstream packages (ai-client, jetpack AI assistant hooks).
  • Replace string-based store references ('core/editor', 'core', 'core/edit-widgets') with proper store descriptors (editorStore, coreStore, editWidgetsStore) for type-safe store access. Reverted due to build failure

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:

  • Verify typecheck passes: cd projects/js-packages/shared-extension-utils && pnpm typecheck
  • To verify the fixes unblock downstream packages, merge the tsgo switch branch and run typecheck for ai-client, publicize, and jetpack.

Changelog

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

@manzoorwanijk manzoorwanijk requested review from a team February 27, 2026 12:13
@manzoorwanijk manzoorwanijk self-assigned this Feb 27, 2026
Copilot AI review requested due to automatic review settings February 27, 2026 12:13
@manzoorwanijk manzoorwanijk added [Status] Needs Review This PR is ready for review. Code Quality labels Feb 27, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

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-shared-extension-utils-type-errors branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/tsgo/fix-shared-extension-utils-type-errors
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/tsgo/fix-shared-extension-utils-type-errors

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
Copy link
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!

Copy link
Contributor

Copilot AI left a comment

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 converts two JavaScript utility functions to TypeScript to fix type errors in downstream packages. The conversion adds proper type definitions and replaces string-based WordPress store references with typed store descriptors for improved type safety.

Changes:

  • Converted get-jetpack-extension-availability.js to TypeScript with exported ExtensionAvailability interface
  • Converted use-autosave-and-redirect/index.js to TypeScript with exported UseAutosaveAndRedirectReturn interface and proper event typing
  • Replaced string-based store references with typed store descriptors from @wordpress/editor, @wordpress/core-data, and @wordpress/edit-widgets

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/js-packages/shared-extension-utils/src/get-jetpack-extension-availability.ts New TypeScript version with typed interfaces for extension availability checking
projects/js-packages/shared-extension-utils/src/get-jetpack-extension-availability.js Removed JavaScript version (converted to TypeScript)
projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts Converted to TypeScript with typed parameters, return interface, and store descriptors
projects/js-packages/shared-extension-utils/package.json Added three WordPress dependencies for typed store access
projects/js-packages/shared-extension-utils/changelog/update-tsgo-fix-shared-extension-utils-type-errors Changelog entry documenting the TypeScript conversion
pnpm-lock.yaml Updated lockfile with new WordPress package dependencies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (5)

projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts:29

  • The window.top property can be null in certain scenarios (e.g., in sandboxed iframes with specific permissions). The type assertion window.top as Window bypasses TypeScript's null checking and could lead to a runtime error if window.top is null. Consider adding a null check before accessing the location property, or use optional chaining: window.top?.location.href = url with appropriate fallback handling.
    projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts:7
  • The noop function is typed as () => {} which returns undefined, but it's used as the default value for the onRedirect parameter which expects ( url: string ) => void. While this works at runtime, it would be more type-safe to define noop with the correct signature: const noop = ( _url: string ) => {}; to match the expected callback signature.
    projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts:58
  • The type assertion for window is overly permissive with { wp?: { customize?: unknown } }. Since the code only checks for the existence of wp.customize without calling it or accessing its properties, a more precise type would be { wp?: { customize?: object } } or even better, define a proper interface for the WordPress customizer API if it's used elsewhere in the codebase.
    projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts:11
  • The Event type used for the event parameters is less specific than the actual events passed to these handlers. Based on usage throughout the codebase (e.g., projects/js-packages/ai-client/src/hooks/use-ai-checkout/index.ts expects MouseEvent< HTMLButtonElement >), these functions are always called from onClick handlers which pass React.MouseEvent. Consider using React.MouseEvent instead of Event for better type safety and consistency with the rest of the codebase.
    projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts:22
  • The return type annotation in the JSDoc comment states "Window | null", but the function doesn't always return these types. When shouldOpenNewWindow is false, it returns the result of assigning to window.top.location.href (which is a string assignment expression). The return type should more accurately be "Window | null | string" or the JSDoc should be updated to match the actual behavior. Alternatively, consider refactoring to make the return value more consistent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Convert get-jetpack-extension-availability.js and
use-autosave-and-redirect/index.js to TypeScript with proper return
type interfaces. Replace string-based store references with store
descriptors for type-safe access.

Fixes TS2339 errors in downstream packages (ai-client, publicize, jetpack).
@manzoorwanijk manzoorwanijk force-pushed the update/tsgo/fix-shared-extension-utils-type-errors branch from b436ee9 to 2ad795a Compare February 27, 2026 12:23
@jp-launch-control
Copy link

jp-launch-control bot commented Feb 27, 2026

Code Coverage Summary

2 files are newly checked for coverage.

File Coverage
projects/js-packages/shared-extension-utils/src/get-jetpack-extension-availability.ts 0/5 (0.00%) 💔
projects/js-packages/shared-extension-utils/src/hooks/use-autosave-and-redirect/index.ts 0/34 (0.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@manzoorwanijk manzoorwanijk marked this pull request as draft February 27, 2026 16:08
@manzoorwanijk manzoorwanijk added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Feb 27, 2026
@manzoorwanijk manzoorwanijk marked this pull request as ready for review February 28, 2026 04:20
Copilot AI review requested due to automatic review settings February 28, 2026 04:20
Copy link
Contributor

Copilot AI left a comment

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 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +16
details?: Array< unknown >;
}

interface JetpackData {
available_blocks?: Record< string, BlockAvailability >;
}

export interface ExtensionAvailability {
available: boolean;
details?: Array< unknown >;
unavailableReason?: string;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

Both the BlockAvailability.details field (line 6) and the ExtensionAvailability.details field (line 15) are typed as Array<unknown>, but the runtime value is a JSON object (PHP associative array), not a JavaScript array. This is confirmed by consumer code such as details.required_plan in plan-utils.js (line 109) and fieldFileAvailability?.details?.required_plan in field-file/edit.js. The correct type should be Record<string, unknown> (or a more specific shape like { required_plan?: string }).

Copilot uses AI. Check for mistakes.
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.

2 participants