feat(messenger): add delegateAll with exhaustive type checking#8338
Draft
cryptodev-2s wants to merge 5 commits intomainfrom
Draft
feat(messenger): add delegateAll with exhaustive type checking#8338cryptodev-2s wants to merge 5 commits intomainfrom
delegateAll with exhaustive type checking#8338cryptodev-2s wants to merge 5 commits intomainfrom
Conversation
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
`delegate` accepts partial action/event lists without compile-time enforcement that all required items are present. `delegateAll` uses a branded intersection type to produce a clear TS error showing exactly which actions or events are missing.
5bd4a95 to
f0e25c9
Compare
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
Messenger.delegate()accepts a partial list of actions/events without compile-time enforcement that all required items are present. This means missing a delegation (e.g., a newly addedAllowedAction) silently compiles and only fails at runtime.delegateAll()wrapsdelegate()with aRequireExhaustivebranded intersection type that produces a clear TypeScript error showing exactly which actions or events are missing from the list. Own-namespace actions of the delegatee are automatically excluded from the check.Example error when an action is missing:
References
Changelog
@metamask/messengerdelegateAll()method — strict alternative todelegate()that requires all external actions and events to be listedMessengerNamespace<M>utility type — extracts the namespace string literal from a Messenger typeRequireExhaustive<Required, Provided>utility type — validates tuple exhaustiveness at compile timeChecklist