MetaMask / core

This monorepo is a collection of packages used across multiple MetaMask clients
MIT License
251 stars 174 forks source link

[composable-controller] Implement type validation of constructor options #4213

Open MajorLift opened 3 months ago

MajorLift commented 3 months ago

Requirements

When initializing a ComposableController class, given a ComposableControllerState type:

  1. A type error should be raised if the list of child controllers specified in the controllers array constructor option does not exactly match the list of controllers included in the ComposableControllerState type.

  2. A type error should be raised if the controller-messenger instance passed into the messenger constructor option has an event allowlist that does not include all of the stateChange events for the list of controllers in the ComposableControllerState type.

References

desi commented 3 months ago

@MajorLift Can you update the ticket to include the solutions you have tried for number 2 above and the roadblocks you hit so that others have that context?

desi commented 3 months ago

Seems like we probably need some spikes to figure out how to solve or approach. So waiting to estimate until we have a chance to do that.

MajorLift commented 2 months ago
MajorLift commented 1 month ago

Following up on the last bullet point in the above comment, the wallet framework proposal also suggests refactoring the ComposableController into a compose function that returns a class instance that composes the input child controllers.

This should make it easier to validate the input params of the compose function, as we can let TypeScript use the input arguments as sources of inference for generic params, and then apply generic constraints.

Here's an example of this concept in action.