[composable-controller] Narrow class and messenger types by parameterizing over child controllers list#3952
Merged
Conversation
MajorLift
changed the base branch from
main
to
240222-composable-controller-type-fixes
February 23, 2024 04:37
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
from
February 23, 2024 04:37
8fb745a to
feb6c38
Compare
MajorLift
force-pushed
the
240222-composable-controller-type-fixes
branch
2 times, most recently
from
February 23, 2024 04:48
0c830ba to
599fd44
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
5 times, most recently
from
February 23, 2024 05:30
ba71fbf to
923d77d
Compare
MajorLift
force-pushed
the
240222-composable-controller-type-fixes
branch
from
February 23, 2024 19:30
bdc167c to
0882483
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
5 times, most recently
from
February 27, 2024 19:04
716af2a to
df1cdc8
Compare
MajorLift
force-pushed
the
240222-composable-controller-type-fixes
branch
from
February 27, 2024 23:33
6ef730e to
0fa97c3
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
from
February 27, 2024 23:35
df1cdc8 to
b2b9059
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
2 times, most recently
from
March 3, 2024 18:02
717c66f to
94019d1
Compare
MajorLift
force-pushed
the
240222-composable-controller-type-fixes
branch
from
March 6, 2024 16:34
0ab242a to
0fa97c3
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
from
March 6, 2024 16:36
94019d1 to
3e9a5d2
Compare
MajorLift
force-pushed
the
240222-composable-controller-type-fixes
branch
from
March 7, 2024 18:26
0fa97c3 to
7d46b06
Compare
MajorLift
force-pushed
the
240220-composable-controller-narrow-typing
branch
from
April 25, 2024 16:02
5f59bf9 to
58ba8bc
Compare
MajorLift
marked this pull request as ready for review
April 25, 2024 16:03
mcmire
self-requested a review
May 28, 2024 16:06
mcmire
reviewed
May 28, 2024
mcmire
left a comment
Collaborator
There was a problem hiding this comment.
Had some questions, but overall makes sense.
|
|
||
| - **BREAKING:** Passing a non-controller into `controllers` constructor option now throws an error ([#3904](https://github.com/MetaMask/core/pull/3904)) | ||
| - **BREAKING:** The `AllowedAction` parameter of the `ComposableControllerMessenger` type is narrowed from `string` to `never`, as `ComposableController` does not use any external controller actions ([#3904](https://github.com/MetaMask/core/pull/3904)) | ||
| - **BREAKING:** The `AllowedActions` parameter of the `ComposableControllerMessenger` type is narrowed from `string` to `never`, as `ComposableController` does not use any external controller actions. ([#3904](https://github.com/MetaMask/core/pull/3904)) |
Collaborator
There was a problem hiding this comment.
It seems that we are updating the changelog for an older version, is this intentional? Are there changes we forgot to include for this version?
Contributor
Author
There was a problem hiding this comment.
Fixed to align with final changelog in PR description: 365aa02
Comment on lines
+191
to
+197
| P extends keyof ComposableControllerState = keyof ComposableControllerState, | ||
| > = P extends string | ||
| ? ComposableControllerState[P] extends StateConstraint | ||
| ? { name: P; state: ComposableControllerState[P] } | ||
| : BaseControllerV1< | ||
| BaseConfig & Record<string, unknown>, | ||
| BaseState & ComposableControllerState[P] |
Collaborator
There was a problem hiding this comment.
Nit: Can we use a non-one-letter name here for clarify? Perhaps ControllerName?
Suggested change
| P extends keyof ComposableControllerState = keyof ComposableControllerState, | |
| > = P extends string | |
| ? ComposableControllerState[P] extends StateConstraint | |
| ? { name: P; state: ComposableControllerState[P] } | |
| : BaseControllerV1< | |
| BaseConfig & Record<string, unknown>, | |
| BaseState & ComposableControllerState[P] | |
| ControllerName extends keyof ComposableControllerState = keyof ComposableControllerState, | |
| > = Key extends string | |
| ? ComposableControllerState[ControllerName] extends StateConstraint | |
| ? { name: ControllerName; state: ComposableControllerState[ControllerName] } | |
| : BaseControllerV1< | |
| BaseConfig & Record<string, unknown>, | |
| BaseState & ComposableControllerState[ControllerName] |
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
Currently, the allow lists of
ComposableControllerMessengerare set tostring, which is too permissive. EachComposableControllerinstance needs typing and allow lists that are specific to its set of input child controllers.To achieve this, the
ComposableControllerclass and its messenger are made polymorphic upon theControllerStatetype, which defines the shape of the composed state.References
Changelog
@metamask/composable-controllerAdded
RestrictedControllerMessengerConstraint, which is the narrowest supertype of all controller-messenger instances.LegacyControllerStateConstraint, a universal supertype for the controller state object, encompassing both BaseControllerV1 and BaseControllerV2 state.ComposableControllerStateConstraint, the narrowest supertype for the composable controller state object.Changed
ComposableControllerclass is now a generic class that expects one generic argumentComposableControllerState(#3952).ComposableControllerclass to be typed correctly, any of its child controllers that extendBaseControllerV1must have an overriddennameproperty that is defined using theas constassertion.Checklist