Skip to content
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

Merged
merged 4 commits into from
Jul 6, 2023

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Jun 30, 2023

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.

@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

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?

Copy link
Member

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

@tjzel tjzel added this pull request to the merge queue Jul 6, 2023
Merged via the queue into main with commit 833c864 Jul 6, 2023
1 check passed
@tjzel tjzel deleted the @tjzel/types/adapters/fix-lacking-cast branch July 6, 2023 13:53
Latropos pushed a commit that referenced this pull request Jul 13, 2023
<!-- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants