core
core copied to clipboard
[composable-controller] Fix `BaseControllerV1Instance` type and make `ChildControllers` a required type parameter
References
- Follow-up from https://github.com/MetaMask/metamask-mobile/pull/10011
Motivation
The ComposableController API is currently not working as expected in downstream consumers (mobile).
Explanation
- The
BaseControllerV1Instancetype needs to be fixed to accommodate controller versions used in mobile that inherit fromBaseControllerV1.Type 'PhishingController | AccountsController | AccountTrackerController | AddressBookController | ... 22 more ... | SwapsController' does not satisfy the constraint 'ControllerInstance'. Type 'AccountTrackerController' is not assignable to type 'ControllerInstance'. Type 'AccountTrackerController' is not assignable to type 'BaseControllerV1Instance'. Types have separate declarations of a private property 'initialConfig'.ts(2344) - The
ChildControllersoptional generic parameter should either be converted into a required parameter, or annotated in jsdoc to make it clear that a full list of controllers can be supplied by the consumer as a type argument. - Fix
LegacyComposableControllerStateConstraintto{ [name: string]: Record<any, any> }, since index signature ofinterfacetypes used for V1 state objects is not fixed tostring. - Test on mobile engine whether runtime checks
isBaseController()andisBaseControllerV1()are functioning as intended.