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

type error when using transition prop with expo 51 and reanimated 3.10 #343

Open
2 of 3 tasks
dannyhw opened this issue May 10, 2024 · 24 comments
Open
2 of 3 tasks

Comments

@dannyhw
Copy link

dannyhw commented May 10, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Do you want this issue prioritized?

  • Yes, I have sponsored
  • Not urgent

Current Behavior

Type '{ duration: number; }' is not assignable to type 'MotiTransitionProp<StyleValueWithReplacedTransforms<ViewStyle | TextStyle | ImageStyle>> | ((custom?: any) => MotiTransition<...>) | undefined'.

Type '{ type: "timing"; duration: number; }' is not assignable to type 'MotiTransitionProp<StyleValueWithReplacedTransforms<ViewStyle | TextStyle | ImageStyle>> | undefined'.

Type '{ type: "timing"; duration: number; delay: number; }' is not assignable to type 'MotiTransitionProp<StyleValueWithReplacedTransforms<ViewStyle | TextStyle | ImageStyle>> | undefined'.

Expected Behavior

No response

Steps To Reproduce

Heres some examples that give me a type error

<MotiView
             from={{ opacity: 0 }}
             animate={{ opacity: 1 }}
             // @ts-ignore TODO moti fix me
             transition={{
               type: "timing",
               duration: 1000,
               delay: index * 1000,
             }}
           >
  <MotiView
       tw="w-full items-center"
       from={{ opacity: 0 }}
       animate={{ opacity: 1 }}
       // @ts-ignore TODO moti fix me
       transition={{
         type: "timing",
         duration: 1000,
       }}
     >
      <View
         from={{ opacity: 0 }}
         animate={{ opacity: 1 }}
         exit={{
           opacity: 0,
         }}
         // @ts-ignore TODO moti fix me
         exitTransition={{ duration: 300 }}
       >
       <View
         from={{ translateY: 128 + 64 + 8, opacity: 0 }}
         animate={{ translateY: 0, opacity: 1 }}
         exit={{
           translateY: 128 + 64 + 8,
           opacity: 0,
         }}
         // @ts-ignore TODO moti fix me
         exitTransition={{ duration: 300 }}
       >

Versions

- Moti: ^0.28.1
- Reanimated: ~3.10.1
- React Native: 0.74.1
- typescript: ^5.3.3

Screenshots

image

Reproduction

https://github.com/dannyhw/moti-types-repro

Run

bun install
bun check
@dannyhw dannyhw changed the title type error when using transition prop with expo 51 and reanimted 3.10 type error when using transition prop with expo 51 and reanimated 3.10 May 10, 2024
@ThatGuySam
Copy link

Getting the same issue when trying to get ahead of migration to Expo 51

"moti": "^0.28.1",
"react-native-reanimated": "~3.10.1",

@dannyhw
Copy link
Author

dannyhw commented May 10, 2024

I'm able to get around the issue by changing to

transition={{
    opacity: {
      type: "timing",
      duration: 1000,
   }
}}

But its a bit tedious with multiple properties

@nandorojo
Copy link
Owner

Fixed #345

@nandorojo
Copy link
Owner

Releasing shortly

@agallio
Copy link

agallio commented May 15, 2024

I'm using version 0.29.0 with Expo SDK 51 and still get the issue. (TypeScript 5.3.3)

image

@nandorojo
Copy link
Owner

@alantoa looks like some people are still getting this on SDK 51, interesting

@alantoa
Copy link
Contributor

alantoa commented May 15, 2024

Hey @agallio, actually it works for me.
What if you run yarn why moti and yarn why react-native-reanimated in your project?
Curious about the version you are actually using.

CleanShot 2024-05-15 at 23 01 06@2x

@alantoa
Copy link
Contributor

alantoa commented May 15, 2024

Also, Can you please show me the type error in your code? (Hover over the error and take a screenshot of the error text.) @agallio

@agallio
Copy link

agallio commented May 15, 2024

Hi @alantoa, thank you for the response. It's working now, I think it was because of my faulty node_modules, when I tried to wipe all the node_modules and yarn.lock and then reinstall, it worked properly.

@alantoa
Copy link
Contributor

alantoa commented May 15, 2024

Got it, that's great!

@RazaShehryar
Copy link

Facing this issue with expo SDK 50.

moti version 0.29
react-native-reanimated version 3.6.2

@nandorojo
Copy link
Owner

You'll need to upgrade RN. The type issue is due to a typo in a react native type. The typo was fixed in RN 0.74

@thoth-seshat
Copy link

@nandorojo I'm using RN 0.74.3 and still see this issue

@nandorojo
Copy link
Owner

please make sure you don't have types/react-native installed

@thoth-seshat
Copy link

thoth-seshat commented Jul 10, 2024

@nandorojo I've uninstalled types/react-native, restarted TS and still see the issue. Deleted node_modules etc

@MarcHbb
Copy link

MarcHbb commented Jul 23, 2024

I have the same issue.

"expo": "~51.0.22",
"react-native": "0.74.3",
"react-native-reanimated": "~3.10.1",
"moti": "0.28"

@markmccoid
Copy link

You need moti v0.29.

Try

npm install moti@latest

@MarcHbb
Copy link

MarcHbb commented Aug 31, 2024

@markmccoid Still have the error after updating to 0.29, event with restarting ts server

@dav1rm
Copy link

dav1rm commented Oct 28, 2024

Same issue here, even it's showing autocomplete options.

"react-native": "0.73.6",
"moti": "^0.29.0",
"react-native-reanimated": "^3.12.1"

image

@nandorojo
Copy link
Owner

Will check on a fix soon, thanks for reporting

@nandorojo
Copy link
Owner

I think it’s actually due to how newer TS versions resolve declaration file import() statements. I fixed something similar in Zeego which wrapped radix.

@Geeknerd1337
Copy link

Geeknerd1337 commented Oct 29, 2024

Also getting this issue

"moti": "^0.29.0",
"react-native": "0.72.10",
"expo": "^49.0.5",
"react-native-reanimated": "~3.3.0",

@bryanmylee
Copy link

This issue occurs due to the type intersection that's being created over multiple definitions of the transition prop.

I'm getting this issue when using motify on a Tamagui View component as well, since it exposes a transition: "allow-discrete" prop.

I'm sure this will be an issue with other libraries as well. My suggestion would be to explicitly specify the prop type as MotiProps & Omit<OriginalProps, keyof MotiProps> to indicate that Moti will take over these props.

@bryanmylee
Copy link

bryanmylee commented Dec 13, 2024

A patch to this function might work:

const Motified = forwardRef<
      Ref,
//      Props &
      Omit<Props, keyof MotiProps> &
        AnimatedProps<Props> &
        MotiProps<Animate> & {
          children?: React.ReactNode
        }
    >(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests