Skip to content

Commit

Permalink
fix: add utils for types (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
heygsc authored Jul 9, 2024
1 parent 94ef364 commit 4c0fd3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/useMotionProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useElementStyle } from './useElementStyle'
import { useElementTransform } from './useElementTransform'
import { usePermissiveTarget } from './usePermissiveTarget'
import { isTransformProp } from './utils/transform'
import { objectEntries } from './utils/type-feature'

/**
* A Composable giving access to both `transform` and `style`objects for a single element.
Expand All @@ -29,12 +30,10 @@ export function useMotionProperties(target: MaybeRef<PermissiveTarget>, defaultV
watch(
motionProperties,
(newVal) => {
Object.entries(newVal).forEach(([key, value]) => {
objectEntries(newVal).forEach(([key, value]) => {
const target = isTransformProp(key) ? transform : style
// @ts-expect-error - Fix errors later for typescript 5
if (target[key] && target[key] === value)
return
// @ts-expect-error - Fix errors later for typescript 5
target[key] = value
})
},
Expand Down
7 changes: 7 additions & 0 deletions src/utils/type-feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function objectEntries<T extends object>(obj: T) {
return Object.entries(obj) as Array<[keyof T, T[keyof T]]>
}

export function objectKeys<T extends object>(obj: T) {
return Object.keys(obj) as Array<keyof T>
}

0 comments on commit 4c0fd3b

Please sign in to comment.