From 25793705f85cbb8532aa28cb7f1e97dc08eff08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= <40713406+tjzel@users.noreply.github.com> Date: Fri, 4 Aug 2023 09:07:46 +0200 Subject: [PATCH] Hotfix: allow transform to be a string in useAnimatedStyle (#4881) ## Summary A few months back RN [added in its types](https://github.com/facebook/react-native/issues/37543) that `transform` could be a `string` - but it's missing in RN `0.72.3` and causes some errors when current version of `react-native-reanimated` is used with RN `0.71`. This PR hotfixes that, allowing `transform` to be a string. Keep in mind that it's definitely not the final form of how `useAnimatedStyle` types should look like - it will be refactored in the future. ## Test plan
This snippet yields errors on `0.71.12` without this change ```TSX function Foo() { const sv = useSharedValue(0); const otherSv = useSharedValue(0); const width = 200; // error here, transform being inferred to `never` const animatedStyle = useAnimatedStyle(() => { return { width: '200%', alignItems: 'center', opacity: interpolate(sv.value, [0, 1], [0, 1], Extrapolation.CLAMP), transform: [ { translateX: interpolate( sv.value, [0, 1], [0, 100], Extrapolation.CLAMP, ), }, { translateY: sv.value + otherSv.value, }, ], }; }, [width]); return ; } ``` --- src/reanimated2/helperTypes.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reanimated2/helperTypes.ts b/src/reanimated2/helperTypes.ts index c20444aec83..7033b22f61b 100644 --- a/src/reanimated2/helperTypes.ts +++ b/src/reanimated2/helperTypes.ts @@ -33,6 +33,7 @@ type TransformsStyle = Pick; type TransformStyleTypes = TransformsStyle['transform'] extends | readonly (infer T)[] + | string | undefined ? T : never;