@@ -83,21 +83,34 @@ export class UIMessenger extends Messenger<
8383 super ( { namespace : UI_MESSENGER_NAMESPACE , captureException } ) ;
8484 }
8585
86- // @ts -expect-error This `call` is purposely not the same `call` from
87- // `Messenger`.
88- async call < ActionType extends UIMessengerActions [ 'type' ] > (
89- actionType : ActionType ,
90- ...params : ExtractActionParameters < UIMessengerActions , ActionType >
91- ) : Promise < Awaited < ExtractActionResponse < UIMessengerActions , ActionType > > > {
86+ /**
87+ * Get the handler for a given action type.
88+ *
89+ * This is called when `call` is invoked on the messenger. We override it here
90+ * to route all calls through the background connection, except for the
91+ * excluded actions.
92+ *
93+ * @param actionType - The action type. This is a unique identifier for this
94+ * action.
95+ * @returns The handler for this action type, or undefined if this action type
96+ * is excluded or not found.
97+ */
98+ protected override getAction (
99+ actionType : UIMessengerActions [ 'type' ] ,
100+ ) : ActionConstraint [ 'handler' ] | undefined {
92101 const excludedActions : string [ ] = EXCLUDED_ACTIONS ;
93102 const anyActionType : string = actionType ;
94103
95- if ( ! excludedActions . includes ( anyActionType ) ) {
96- throw new Error ( `Action '${ actionType } ' has not been exposed to the UI` ) ;
104+ if ( excludedActions . includes ( anyActionType ) ) {
105+ throw new Error (
106+ `The action "${ actionType } " has not been exposed to the UI.` ,
107+ ) ;
97108 }
98109
99- // @ts -expect-error: Type of handler is not compatible.
100- return await Engine . controllerMessenger . call ( actionType , ...params ) ;
110+ return ( ...args : unknown [ ] ) =>
111+ // @ts -expect-error: `unknown[]` is not assignable to `args`, but the type
112+ // here is checked in `call`, so this is safe.
113+ Engine . controllerMessenger . call ( actionType , ...args ) ;
101114 }
102115
103116 /**
0 commit comments