core icon indicating copy to clipboard operation
core copied to clipboard

[composable-controller] Fix `BaseControllerV1Instance` type and make `ChildControllers` a required type parameter

Open MajorLift opened this issue 1 year ago • 0 comments

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 BaseControllerV1Instance type needs to be fixed to accommodate controller versions used in mobile that inherit from BaseControllerV1.
    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 ChildControllers optional 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 LegacyComposableControllerStateConstraint to { [name: string]: Record<any, any> }, since index signature of interface types used for V1 state objects is not fixed to string.
  • Test on mobile engine whether runtime checks isBaseController() and isBaseControllerV1() are functioning as intended.

MajorLift avatar Jun 21 '24 22:06 MajorLift