From b1772f2273009233b72ad44fe32170831080bef4 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 22 Apr 2021 10:53:10 -0230 Subject: [PATCH] Remove ComposableController generic type parameters These generic type parameters weren't really used in practice. They were passed to the `messagingSystem`, but we erased the type of the messaging system in the one place that we call it, making the more specific types pointless. You can tell that they weren't useful because they were never set in tests, and everything still worked. --- src/ComposableController.ts | 18 ++++++------------ src/ControllerMessenger.ts | 9 +-------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/ComposableController.ts b/src/ComposableController.ts index 3b17a738c4..c30594c1e8 100644 --- a/src/ComposableController.ts +++ b/src/ComposableController.ts @@ -1,8 +1,5 @@ import BaseController from './BaseController'; -import { - RestrictedControllerMessenger, - EventConstraint, -} from './ControllerMessenger'; +import { RestrictedControllerMessenger } from './ControllerMessenger'; /** * List of child controller instances @@ -21,18 +18,15 @@ export type ControllerList = ( /** * Controller that can be used to compose multiple controllers together */ -export class ComposableController< - Events extends EventConstraint, - AllowedEvents extends string -> extends BaseController { +export class ComposableController extends BaseController { private controllers: ControllerList = []; private messagingSystem?: RestrictedControllerMessenger< 'ComposableController', never, - Events, + any, never, - AllowedEvents + any >; /** @@ -51,9 +45,9 @@ export class ComposableController< messenger?: RestrictedControllerMessenger< 'ComposableController', never, - Events, + any, never, - AllowedEvents + any >, ) { super( diff --git a/src/ControllerMessenger.ts b/src/ControllerMessenger.ts index 9724b027b8..570d2ee1a2 100644 --- a/src/ControllerMessenger.ts +++ b/src/ControllerMessenger.ts @@ -24,14 +24,7 @@ type ExtractEventPayload = Event extends { type: T; payload: infer P } : never; type ActionConstraint = { type: string; handler: (...args: any) => unknown }; - -/** - * A valid ControllerMessenger Event. - * - * This type is used to constrain generic Event parameters, to ensure valid - * Event types are given. - */ -export type EventConstraint = { type: string; payload: unknown[] }; +type EventConstraint = { type: string; payload: unknown[] }; /** * A namespaced string