-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TypeScript issue with useAnimatedProps #4653
Conversation
src/reanimated2/helperTypes.ts
Outdated
@@ -115,3 +116,11 @@ export type AnimateProps<P extends object> = NonStyleAnimatedProps<P> & | |||
}; | |||
|
|||
export type AnimatedProps<P extends object> = AnimateProps<P>; | |||
|
|||
export type PropsAdapterFunction = (props: Record<string, unknown>) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type PropsAdapterFunction = (props: Record<string, unknown>) => void; | |
export type AnimatedPropsAdapterFunction = (props: Record<string, unknown>) => void; |
const nativePropsToAdd: { [key: string]: boolean } = {}; | ||
// eslint-disable-next-line no-unused-expressions | ||
nativeProps?.forEach((prop) => { | ||
nativePropsToAdd[prop] = true; | ||
}); | ||
addWhitelistedNativeProps(nativePropsToAdd); | ||
return adapter; | ||
} | ||
}) as createAnimatedPropAdapterType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to cast the whole function instead of just casting the return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not a 'hot fix' I think we should avoid type casting
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary During the migration from manual types, the proper typing of "useAnimatedProps" has proven to be quite challenging. As a result, I had to resort to casting it to its previous type, but unfortunately, I missed some places. ## Test plan In our new docs the given [example](https://reanimated-beta-docs.swmansion.com/docs/core/useAnimatedProps#adapters-) doesn't work. After applying these changes it's fixed.
Summary
During the migration from manual types, the proper typing of "useAnimatedProps" has proven to be quite challenging. As a result, I had to resort to casting it to its previous type, but unfortunately, I missed some places.
Test plan
In our new docs the given example doesn't work.
After applying these changes it's fixed.