Optimize type params for Messenger.delegate/revoke#8748
Merged
Conversation
When TypeScript type-checks arguments to `Messenger.delegate` and `Messenger.revoke` it can produce the error "Expression produces a union type that is too complex to represent" if the delegatee contains a large number of capabilities and/or there are large number of capabilities being delegated or revoked. This happens because when TypeScript evaluates `MessengerActions<Delegatee> & Action` or `MessengerEvents<Delegatee> & Event` it needs to recursively compute every combination of action/event type — handlers, types used within handlers, everything. The possibility of this error has always been present, but was excerbated by recent changes to the `InternalAccount` type in `keyring-api`, which added support for Tron and Stellar. All of this computing is wasteful. All we really need is an intersection of action/event type strings. This commit changes the types for `DelegatedActions` and `DelegatedEvents` to reflect this fact. These changes should be type-compatible since the end result is still the same.
cryptodev-2s
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
When TypeScript type-checks arguments to
Messenger.delegateandMessenger.revokeit can produce the error "Expression produces a union type that is too complex to represent" if the delegatee contains a large number of capabilities and/or there are large number of capabilities being delegated or revoked. This happens because when TypeScript evaluatesMessengerActions<Delegatee> & ActionorMessengerEvents<Delegatee> & Eventit needs to recursively compute every combination of action/event type — handlers, types used within handlers, everything. The possibility of this error has always been present, but was excerbated by recent changes to theInternalAccounttype inkeyring-api, which added support for Tron and Stellar.All of this computing is wasteful. All we really need is an intersection of action/event type strings. This commit changes the types for
DelegatedActionsandDelegatedEventsto reflect this fact. These changes should be type-compatible since the end result is still the same.References
Recently a change was made in Mobile to work around this problem. See: MetaMask/metamask-mobile#29621
Checklist
Note
Medium Risk
Public TypeScript API typings for
Messenger.delegate/Messenger.revokechange, which could affect downstream type-checking even though runtime behavior is untouched. Risk is limited to compile-time compatibility and inference/regression in complex consumer typings.Overview
Reduces TypeScript type-checker blowups in
Messenger.delegateandMessenger.revokeby narrowingDelegatedActions/DelegatedEventsto intersections of action/event type strings (rather than intersecting full action/event unions), aiming to avoid TS2590 “union type too complex” errors.Updates the messenger package changelog to note the fix under Unreleased.
Reviewed by Cursor Bugbot for commit cdf1305. Bugbot is set up for automated code reviews on this repo. Configure here.