Skip to content

Commit f781594

Browse files
committed
Add ts-expect-error for messenger subscriptions that are guaranteed to only happen for child controller events
1 parent b8bce30 commit f781594

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/composable-controller/src/ComposableController.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ export class ComposableController<
182182
throw new Error(`${name} - ${INVALID_CONTROLLER_ERROR}`);
183183
}
184184
try {
185-
this.messenger.subscribe(
186-
`${name}:stateChange`,
187-
(childState: StateConstraint) => {
188-
this.update((state) => {
189-
// Type assertion is necessary for property assignment to a generic type. This does not pollute or widen the type of the asserted variable.
190-
// @ts-expect-error "Type instantiation is excessively deep"
191-
(state as ComposableControllerStateConstraint)[name] = childState;
192-
});
193-
},
194-
);
185+
this.messenger.subscribe<
186+
// The type intersection with "ComposableController:stateChange" is added by one of the `Messenger.subscribe` overloads, but that constraint is unnecessary here,
187+
// since this method only subscribes the messenger to child controller `stateChange` events.
188+
// @ts-expect-error "Type '`${string}:stateChange`' is not assignable to parameter of type '"ComposableController:stateChange" & ChildControllerStateChangeEvents<ComposableControllerState>["type"]'."
189+
ChildControllerStateChangeEvents<ComposableControllerState>['type']
190+
>(`${name}:stateChange`, (childState: StateConstraint) => {
191+
this.update((state) => {
192+
// Type assertion is necessary for property assignment to a generic type. This does not pollute or widen the type of the asserted variable.
193+
// @ts-expect-error "Type instantiation is excessively deep"
194+
(state as ComposableControllerStateConstraint)[name] = childState;
195+
});
196+
});
195197
} catch (error: unknown) {
196198
// False negative. `name` is a string type.
197199
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions

0 commit comments

Comments
 (0)