pmndrs / react-spring

✌️ A spring physics based React animation library
http://www.react-spring.dev/
MIT License
28k stars 1.19k forks source link

Typedef problem for the interpolate call. #712

Closed richtera closed 5 years ago

richtera commented 5 years ago

🐛 Bug Report

The interpolate call is defined to get an array of type T but in fact gets applied so that the arguments are spread.

To Reproduce

In typescript you will get compiler warnings saying that the method doesn't match. So the typedef in the npm assumed you would do something like:

local.interpolate(([x, y]) => ...);

instead of the actual

local.interpolate((x, y) => ...);

https://github.com/react-spring/react-spring/blob/f1c601ab3375487f837bd2edbfc31ccbc2ef0e49/types/web.d.ts#L46

I think the line should say

<U>(interpolator: (...params: T) => U): OpaqueInterpolation<U>

But I am not sure if the spread operator works for typedefs but in essence it needs to be defined as a method with multiple args.

Expected behavior

No type error.

Link to repro (highly encouraged)

This is a private repo, but this should easily display the issue image

Here is a hack that also shows why and how to get around it

<animated.div {...bind()} style={{
      transform: local.interpolate(((x, y) => `translate3d(${x}px, ${y}px,0)`) as ((args: number[]) => string)),
    }} {...rest}/>

Environment

aleclarson commented 5 years ago

This is fixed in v9.0.0-beta

npm install react-spring@next

Closing this, since there's no one maintaining the v8 types.