Typescript with Reanimated and Animated.AnimateProps #4188
-
trying to type my project (fix errors after upgrading deps to v3 and adding Animated as default view) and i get a problem on a few props because of first: Is there a type that you provide for your ViewProps? because
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seems that you're encountering type errors when trying to upgrade dependencies to v3 and add Animated as the default view in your project. Specifically, you're running into issues with the props for Animated components, which are causing TypeScript errors. The problem with the testID prop becoming a string | AnimateSharedValue is likely due to the fact that the AnimateSharedValue type is being included in the union type. To resolve this issue, you could try explicitly typing the testID prop as a string, like this:
Regarding the issue with the createContext provider, it seems that the ReactNode type is being extended to include Animated.SharedValue. One way to handle this could be to define a custom type that extends ReactNode but excludes the Animated.SharedValue type, like this:
Then, you can use this custom type as the generic type for your provider, like this:
Regarding your question about the AnimateProps type, it seems that this type includes all props of P, except for the style prop, which is replaced with SharedValue<P['style']>. If you want to omit certain props from the AnimateProps type, you could try creating a custom type that excludes those props, like this:
Then, you can use this custom type instead of AnimateProps, like this:
This will create an animated version of the View component, with all props except for testID included in the AnimateProps type. |
Beta Was this translation helpful? Give feedback.
It seems that you're encountering type errors when trying to upgrade dependencies to v3 and add Animated as the default view in your project. Specifically, you're running into issues with the props for Animated components, which are causing TypeScript errors.
The problem with the testID prop becoming a string | AnimateSharedValue is likely due to the fact that the AnimateSharedValue type is being included in the union type. To resolve this issue, you could try explicitly typing the testID prop as a string, like this:
Regarding the issue with the createContext provider, it seems that the ReactNode type is being extended to include Animated.SharedValue. One way to handle t…