Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MajorLift opened this issue Apr 25, 2024 · 3 comments
Open

Comments

@MajorLift
Copy link
Contributor

MajorLift commented Apr 25, 2024

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
Copy link

desi commented Apr 25, 2024

@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
Copy link

desi commented Apr 25, 2024

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
Copy link
Contributor Author

MajorLift commented May 1, 2024

  • controllers:

    • Validating with a union type consisting of the child controllers allows controllers lists that are incomplete.
    • Validating with a tuple type consisting of the child controllers forces us to pass in a controllers list that matches the order of the tuple type, not just the contents.
      • Because the tuple type is likely to be derived from a union type, its order cannot necessarily be determined based on the order of controllers presented in the ComposableControllerState type.
  • messenger:

    • Given an event allowlist T, and U s.t. U <: T, TypeScript does not recognize that RestrictedControllerMessenger<..., U> <: RestrictedControllerMessenger<..., T>.
    • Wrap class constructor into a factory function that takes the event allowlist as a parameter, and validate that parameter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants