diff --git a/src/composables/use-experience-controls.composable.ts b/src/composables/use-experience-controls.composable.ts index b8984b43..8e14b8e8 100644 --- a/src/composables/use-experience-controls.composable.ts +++ b/src/composables/use-experience-controls.composable.ts @@ -11,17 +11,28 @@ import { useStore } from './use-store.composable'; * * @returns The experience controls property value. */ -export const useXControls = ({ - path, - defaultValue -}: { - path: never; - defaultValue?: string | number | boolean | number[]; -}): ComputedRef => { - const experienceControls = (useStore('experienceControls') as unknown as ExperienceControlsState) - .controls.controls; +// Rename +export const useExperienceControls = (): { + getControlFromPath: (path: string, defaultValue?: SomeType) => ComputedRef; +} => { + const experienceControls = (useStore('experienceControls') as ExperienceControlsState).controls + .controls; - return computed(() => { - return getSafePropertyChain(experienceControls, path, defaultValue); - }); +// extracted the current logic to a function. The function can be typed so the return type is known and also it infers the return type from the default value + const getControlFromPath = ( + path: string, + defaultValue?: SomeType + ): ComputedRef => { + return computed(() => { + return getSafePropertyChain( + experienceControls, + path as ExtractPath, + defaultValue + ) as SomeType; + }); + }; + + return { + getControlFromPath + }; };