From 3fd26eb6544809d6a3e00a45e916f5e9fd61ae2a Mon Sep 17 00:00:00 2001 From: Christian Pillsbury Date: Mon, 18 Aug 2025 13:01:48 -0500 Subject: [PATCH] fix(media-store): resolve TypeScript error in dispatch method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add proper type predicate to filter for FacadeProp objects - Use type assertion for setter calls to handle generic state objects - Improve type safety by replacing 'any' types with proper interfaces - Fix TS2345 error: "Argument of type 'number | boolean' is not assignable to parameter of type 'never'" - Maintain runtime flexibility while preserving compile-time type checking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- packages/core/media-store/src/factory.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/media-store/src/factory.ts b/packages/core/media-store/src/factory.ts index 80bbdd48..5f89fd3c 100644 --- a/packages/core/media-store/src/factory.ts +++ b/packages/core/media-store/src/factory.ts @@ -31,7 +31,9 @@ export type FacadeProp = ReadonlyFacadeProp & { set: FacadeSetter; /** @TODO We probably need to refactor this for more complex cases where we can't simply translate to a setter */ actions: { - [k: string]: (val: CustomEvent) => ReturnType>; + [k: string]: ( + val: Pick, 'type' | 'detail'>, + ) => ReturnType>; }; }; @@ -49,7 +51,7 @@ export function createMediaStore({ media?: any; stateMediator: Partial & Pick; }) { - const stateOwners: any = {}; + const stateOwners: StateOwners = {}; const store = map({}); const stateUpdateHandlers: Record void> = {}; const keys = Object.keys(stateMediator); @@ -90,18 +92,23 @@ export function createMediaStore({ } return { - dispatch(action: any) { + dispatch(action: Pick, 'type' | 'detail'>) { const { type, detail } = action; if (type === 'mediaelementchangerequest') { updateStateOwners({ media: detail }); } else { for (const stateObject of Object.values(stateMediator).filter( - (stateMediator) => 'set' in stateMediator, + ( + stateMediatorEntry, + ): stateMediatorEntry is FacadeProp => + 'set' in stateMediatorEntry, )) { const { set, actions } = stateObject; - if (type in actions) { - set(actions[type as keyof typeof actions](), stateOwners); + if (actions[type]) { + const actionFn = actions[type]; + const actionValue = actionFn(action); + (set as FacadeSetter)(actionValue, stateOwners); } } }