wcandillon / react-native-redash

The React Native Reanimated and Gesture Handler Toolbelt
https://wcandillon.gitbook.io/redash/
MIT License
1.99k stars 117 forks source link

Type error when assigning readonly Matrix to mutable shared value in react-native-reanimated #510

Open demedos opened 1 year ago

demedos commented 1 year ago

As Matrix4 is declared as a readonly array, it is impossibile to re-assign it as an AnimatableValue and to properly animate some transitions. I know this is expected behavior, but any idea on how to implement the following code maintaining the readonly type safety?

Code example:

import { useSharedValue, withTiming } from 'react-native-reanimated';
import { identity4 } from 'react-native-redash';

const matrix = useSharedValue(identity4); // matrix is expected to be mutable
matrix.value = withTiming(identity4); // This assignment attempts to assign a readonly array to a mutable one

Error:

Argument of type 'Matrix4' is not assignable to parameter of type 'AnimatableValue'.
The type 'readonly [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.ts(2345)