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

Property 'push' does not exist on type #684

Open
stereodenis opened this issue Sep 26, 2024 · 2 comments
Open

Property 'push' does not exist on type #684

stereodenis opened this issue Sep 26, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@stereodenis
Copy link

Property 'push' does not exist on type 'readonly (({ perspective: AnimatableNumericValue; } & { rotate?: undefined; rotateX?: undefined; rotateY?: undefined; rotateZ?: undefined; scale?: undefined; scaleX?: undefined; ... 5 more ...; matrix?: undefined; }) | ... 11 more ... | ({ ...; } & { ...; }))[]'.

node_modules/react-native-reanimated-carousel/src/layouts/stack.ts:99

@dosubot dosubot bot added the bug Something isn't working label Sep 26, 2024
Copy link

dosubot bot commented Sep 26, 2024

Hey @stereodenis! I'm here to help you with any bugs or questions you have while waiting for a human maintainer. Let's tackle this together!

I found a similar closed issue that might be relevant to your problem: 我完全根据文档例子使用,却报错无法使用。 [1].

The error you're encountering, "Property 'push' does not exist on type...", suggests that the array transform is being treated as a read-only array. The type definition of the array being manipulated in stack.ts:99 is TransformsStyle["transform"] [2].

To resolve this issue, you can try casting the array to a mutable type before using the push method. Here's an example of how you might do this:

const transform: TransformsStyle["transform"] = [] as TransformsStyle["transform"] & { push: any[]["push"] };

This will allow you to use the push method on the transform array without TypeScript throwing an error.

To continue talking to Dosu, mention @dosu.

@zhenkaGo
Copy link

@stereodenis this patch should fix this issue.
I will make PR later.

diff --git a/src/layouts/stack.ts b/src/layouts/stack.ts
index 77a9b57c03e1001bb73a7aff171b2cf276d45f0c..024c489843d729031adf09894b319fc96297ee56 100644
--- a/src/layouts/stack.ts
+++ b/src/layouts/stack.ts
@@ -49,7 +49,6 @@ export function horizontalStackLayout(modeConfig: ILayoutConfig = {}) {
       rotateZDeg = 30,
     } = modeConfig;
 
-    const transform: TransformsStyle["transform"] = [];
     const { validLength, value, inputRange } = getCommonVariables({
       showLength: showLength!,
       value: _value,
@@ -62,12 +61,6 @@ export function horizontalStackLayout(modeConfig: ILayoutConfig = {}) {
       snapDirection,
     });
 
-    const styles: ViewStyle = {
-      transform,
-      zIndex,
-      opacity,
-    };
-
     let translateX: number;
     let scale: number;
     let rotateZ: string;
@@ -112,8 +105,8 @@ export function horizontalStackLayout(modeConfig: ILayoutConfig = {}) {
         Extrapolate.CLAMP,
       )}deg`;
     }
-
-    transform.push(
+    
+    const transform: TransformsStyle["transform"] = [
       {
         translateX: translateX!,
       },
@@ -122,8 +115,14 @@ export function horizontalStackLayout(modeConfig: ILayoutConfig = {}) {
       },
       {
         rotateZ: rotateZ!,
-      },
-    );
+      }
+    ];
+    
+    const styles: ViewStyle = {
+      transform,
+      zIndex,
+      opacity,
+    };
 
     return styles;
   };
@@ -164,7 +163,6 @@ export function verticalStackLayout(modeConfig: ILayoutConfig = {}) {
       opacityInterval = 0.1,
       rotateZDeg = 30,
     } = modeConfig;
-    const transform: TransformsStyle["transform"] = [];
     const { validLength, value, inputRange } = getCommonVariables({
       showLength: showLength!,
       value: _value,
@@ -177,12 +175,6 @@ export function verticalStackLayout(modeConfig: ILayoutConfig = {}) {
       snapDirection,
     });
 
-    const styles: ViewStyle = {
-      transform,
-      zIndex,
-      opacity,
-    };
-
     let translateX: number;
     let scale: number;
     let rotateZ: string;
@@ -241,7 +233,7 @@ export function verticalStackLayout(modeConfig: ILayoutConfig = {}) {
       );
     }
 
-    transform.push(
+    const transform = [
       {
         translateX: translateX!,
       },
@@ -253,8 +245,14 @@ export function verticalStackLayout(modeConfig: ILayoutConfig = {}) {
       },
       {
         translateY: translateY!,
-      },
-    );
+      }
+    ];
+    
+    const styles: ViewStyle = {
+      transform,
+      zIndex,
+      opacity,
+    };
 
     return styles;
   };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants