moti icon indicating copy to clipboard operation
moti copied to clipboard

fix `motify()` type definition conflict for `transition` prop

Open bryanmylee opened this issue 1 year ago • 12 comments

Moti takes over the transition prop to define transition configs, but this might conflict with existing transition props on the original component.

While the implementation simply ignores passing transition to the original component, the type definition tries to merge the type declaration for both props, which sometimes results in impossible type intersections.

This change removes that possibility by omitting any keyof MotiProps from the component's original prop definition.

bryanmylee avatar Dec 13 '24 10:12 bryanmylee

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
moti ❌ Failed (Inspect) Dec 13, 2024 10:40am

vercel[bot] avatar Dec 13 '24 10:12 vercel[bot]

This should also solve https://github.com/nandorojo/moti/issues/343

bryanmylee avatar Dec 13 '24 10:12 bryanmylee

Looks reasonable, I assume this fixed it for you?

nandorojo avatar Dec 13 '24 13:12 nandorojo

It does sometimes but I keep running into a TypeScript limitation TS2590: Expression produces a union type that is too complex to represent.

I'm not sure what the best approach to resolving performance issues is.

bryanmylee avatar Dec 13 '24 13:12 bryanmylee

What if you just manually omit transition?

nandorojo avatar Dec 13 '24 13:12 nandorojo

It still causes the type to blow up in complexity. I can't say for sure, but I think using Omit on Props in general is causing the issue.

bryanmylee avatar Dec 13 '24 15:12 bryanmylee

In my experience that wouldn't quite be what causes it to blow up, more likely the depth of transition...for example if we removed the generic on the transition prop I wonder what would happen

nandorojo avatar Dec 13 '24 15:12 nandorojo

Also is this the latest TS version

nandorojo avatar Dec 13 '24 15:12 nandorojo

Thanks for digging in btw

nandorojo avatar Dec 13 '24 15:12 nandorojo

I'm not on the latest TypeScript but on a pretty late version 5.3.3.

bryanmylee avatar Dec 13 '24 15:12 bryanmylee

I think the problem originates from newer react-native and react-native-reanimated versions. I wonder if upgrading those + TypeScript in the moti repo would fix it.

Wrapping other dependencies and their types can be tough...

nandorojo avatar Dec 14 '24 21:12 nandorojo

When I have time, I'd be happy to explore this more.

bryanmylee avatar Dec 15 '24 15:12 bryanmylee