Closed richtera closed 5 years ago
The interpolate call is defined to get an array of type T but in fact gets applied so that the arguments are spread.
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.
No type error.
This is a private repo, but this should easily display the issue
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}/>
react-spring
react
This is fixed in v9.0.0-beta
npm install react-spring@next
Closing this, since there's no one maintaining the v8 types.
🐛 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:
instead of the actual
https://github.com/react-spring/react-spring/blob/f1c601ab3375487f837bd2edbfc31ccbc2ef0e49/types/web.d.ts#L46
I think the line should say
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
Here is a hack that also shows why and how to get around it
Environment
react-spring
8.0.25react
16.8.6