Skip to content

tsgo: Fix js-packages/connection type errors#47380

Open
manzoorwanijk wants to merge 1 commit intotrunkfrom
update/tsgo/fix-use-connection-type-errors
Open

tsgo: Fix js-packages/connection type errors#47380
manzoorwanijk wants to merge 1 commit intotrunkfrom
update/tsgo/fix-use-connection-type-errors

Conversation

@manzoorwanijk
Copy link
Member

Fixes MONOREP-377

Proposed changes:

  • Fix tsgo type errors in js-packages/connection by converting the useConnection hook from JavaScript to TypeScript.

    TS2339 — Properties don't exist on type '{}':
    Converted components/use-connection/index.jsx to .ts with UseConnectionProps and UseConnectionReturn interfaces, giving the hook explicit parameter and return types. Extracted types into a separate types.ts file. Added concrete UserConnectionData, WpcomUser, and RegistrationError interfaces so downstream consumers (e.g. my-jetpack) get proper property access through ReturnType<typeof useConnection>.

    TS2339 — response does not exist on type false:
    Changed registrationError?.response?.code to a truthiness-narrowed ternary in connect-screen/basic/index.tsx, since optional chaining doesn't narrow the false branch of the union type.

    Untyped useSelect callbacks:
    Added explicit StoreSelector type for the select parameter and cast store selector return values to their expected types, replacing the opaque getConnectionStatus() spread with individually typed properties.

    window.location = redirectUri:
    Changed to window.location.href = redirectUri for type-safe assignment.

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

N/A — Internal tooling change.

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

No.

Testing instructions:

  • Run pnpm typecheck and verify cascading errors are also resolved.
  • Verify that the connection screen still works as expected (no runtime behavior changes).

Changelog

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

Note: This is not the type of TypeScript I like but it's more like a band-aid for the problem. The real fix would be to convert the whole connection data store to TS and use the store object in useSelect and useDispatch instead of the store ID.

@manzoorwanijk manzoorwanijk requested review from a team February 27, 2026 11:32
@manzoorwanijk manzoorwanijk self-assigned this Feb 27, 2026
Copilot AI review requested due to automatic review settings February 27, 2026 11:32
@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-use-connection-type-errors branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/tsgo/fix-use-connection-type-errors
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/tsgo/fix-use-connection-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 addresses TypeScript (tsgo) type errors in the @automattic/jetpack-connection package by converting the useConnection hook to TypeScript and tightening up typing around connection store selectors and error handling.

Changes:

  • Convert components/use-connection from JS to TS, introducing explicit prop/return interfaces and additional data types.
  • Update selector usage in useConnection to add explicit typing/casts and avoid spreading opaque selector return values.
  • Fix a union-narrowing issue in the connect screen (registrationError can be false) and use window.location.href for type-safe redirects.

Reviewed changes

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

Show a summary per file
File Description
projects/js-packages/connection/package.json Updates the subpath export for ./use-connection to point at the new TS entry file.
projects/js-packages/connection/components/use-connection/types.ts Adds exported TS interfaces for hook props/return types and related data shapes.
projects/js-packages/connection/components/use-connection/index.ts Converts the hook implementation to TS and applies typed useSelect/selector reads and redirect typing.
projects/js-packages/connection/components/connect-screen/basic/index.tsx Adjusts registrationError access to properly narrow the false union branch.
projects/js-packages/connection/changelog/update-tsgo-fix-use-connection-type-errors Adds a patch changelog entry for the TS conversion.
Comments suppressed due to low confidence (1)

projects/js-packages/connection/components/use-connection/index.ts:60

  • The hook signature claims to return userConnectionData: UserConnectionData, but here getUserConnectionData() is only type-cast and not runtime-normalized. Since the selector can return false, this can leak false to callers who will treat it as an object based on the TS types. Consider coercing falsy values to a safe default (or updating the hook return type to include false).

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

Convert useConnection hook from JS to TypeScript with explicit
UseConnectionProps and UseConnectionReturn interfaces, fixing 5
TS2339 errors caused by tsgo inferring the return type as '{}'.
@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/connection/components/use-connection/index.ts 23/27 (85.19%) 💚
projects/js-packages/connection/components/use-connection/types.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

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