react-spring icon indicating copy to clipboard operation
react-spring copied to clipboard

Wrong value.interpolate() type

Open vinisxs opened this issue 7 years ago • 4 comments

I tried to convert the "GESTURES (PULL & RELEASE)" example to typescript and the types don't match with reallity.

const [{ xy }, set] = useSpring(() => ({ xy: [0, 0] })) returns xy: OpaqueInterpolation<number[]> so xy.interpolate() expects (number[]) => string but in fact it only works with (number, number) => string

I had to use as any to make it work...

const translate = (x: number, y: number) => `translate3d(${x}px, ${y}px, 0)`;
return <animated.div {...bind()} style={{ transform: xy.interpolate(translate as any) }} />

vinisxs avatar Feb 25 '19 22:02 vinisxs

for now i think that's fine, @jacobrask is currently making super efforts to transform the lib to TS, then we won't have to rely on contrib types - but it's gonna take a while.

drcmda avatar Feb 27 '19 16:02 drcmda

I'm soon done with the interpolation + animated types and I will back port (copy paste) them to the current external type definitions first. Your case is supported by the new annotations, as AnimatedArrays will properly expand to function arguments.

Just need to do some more testing, all APIs will now return a new SpringValue type which can be assigned to properties of animated components, but I need to make sure nothing breaks for people who wrap with styled-components etc.

jacobrask avatar Feb 27 '19 18:02 jacobrask

@jacobrask Please create a "draft PR" of your work on the types, so I can help out and use them locally. Thanks!

aleclarson avatar Apr 01 '19 17:04 aleclarson

Everything I have done so far is currently merged into master

jacobrask avatar Apr 01 '19 20:04 jacobrask