fix(media-store): resolve TypeScript error in dispatch method

- 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 <noreply@anthropic.com>
This commit is contained in:
Christian Pillsbury
2025-08-19 08:41:08 -07:00
committed by Christian Pillsbury
co-authored by Claude
parent 4662dbcbb1
commit 3fd26eb654
+13 -6
View File
@@ -31,7 +31,9 @@ export type FacadeProp<T, S = T, D = T> = ReadonlyFacadeProp<T, D> & {
set: FacadeSetter<S>;
/** @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<any>) => ReturnType<FacadeGetter<T, D>>;
[k: string]: (
val: Pick<CustomEvent<any>, 'type' | 'detail'>,
) => ReturnType<FacadeGetter<T, D>>;
};
};
@@ -49,7 +51,7 @@ export function createMediaStore({
media?: any;
stateMediator: Partial<StateMediator> & Pick<StateMediator, 'mediaPaused'>;
}) {
const stateOwners: any = {};
const stateOwners: StateOwners = {};
const store = map<any>({});
const stateUpdateHandlers: Record<string, () => void> = {};
const keys = Object.keys(stateMediator);
@@ -90,18 +92,23 @@ export function createMediaStore({
}
return {
dispatch(action: any) {
dispatch(action: Pick<CustomEvent<any>, '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<any, any, any> =>
'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<any>)(actionValue, stateOwners);
}
}
}