MetaMask / MetaMask/metamask-extension
[`MetamaskController` A.7] Reconcile `registerWalletServices` messenger typing
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
**Sub-epic:** [#41736 — `MetamaskController` decomposition: wallet-services completion](https://github.com/MetaMask/metamask-extension/issues/41736)
**Files:** [`app/scripts/lib/messenger.ts`](https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/lib/messenger.ts), `app/scripts/lib/wallet-services/register.ts` (created by A.1–A.6), each module's `registerActions` export
**Size:** M
## Problem
After A.1–A.6, `register.ts` takes `RootMessenger` with default generics and casts to `never` before calling each module's `registerActions`. The cast exists because `RootMessenger` is generic over `AllowedActions` (see [`messenger.ts`](https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/lib/messenger.ts): `RootMessenger`) — there is no closed union to constrain against. Comments that describe the cast as a "missing union entries" problem are misleading; the real fix is to compose a `WalletServicesActions` union and type `registerWalletServices` against it.
## Solution
1. Each module exports its action types as an `XxxActions` union.
2. `register.ts` composes `type WalletServicesActions = VaultManagementActions | AccountManagementActions | ...` (and the corresponding events union).
3. Re-type `registerWalletServices(messenger: RootMessenger)`.
4. Update `MetamaskController`'s `getRootMessenger()` callsite to pass matching generics.
5. `tsc` will flag any wrong action name that slipped through during A.1–A.6 — that's the gate.
## Acceptance criteria
- [ ] `registerWalletServices` typed as `RootMessenger`
- [ ] `register.ts` has no cast
- [ ] `MetamaskController`'s `getRootMessenger()` callsite is generic-parameterized
- [ ] `tsc` passes
## Dependencies
**A.1–A.6** — all module action names must be final before the union can be composed.
Contributor guide
Research direction
Start with app/scripts/lib/messenger.ts to understand the RootMessenger generics, then read app/scripts/lib/wallet-services/register.ts and each module's registerActions export. Compose the action and event unions, update the registerWalletServices type and MetamaskController getRootMessenger callsite, and run tsc; done means the cast is gone and type-checking passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100