pmndrs / react-spring

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

[bug]: render prop within <Spring> is inferred to any #2006

Open astj opened 2 years ago

astj commented 2 years ago

Which react-spring target are you using?

What version of react-spring are you using?

9.5.5 (maybe 9.5.3+?)

What's Wrong?

When <Spring> component used with render props, TypeScript compiler infers render prop as any, which makes compiler emit errors when noImplicitAny enabled.

With attached CodeSandbox (just using <Spring> component taken from https://react-spring.dev/components/spring#and-this-is-how-you-create-a-chain ), react-spring 9.5.2 works fine and infers styles prop as {opacity: SpringValue<number>, color: SpringValue<string>}. But 9.5.3+ infers it as any.

To Reproduce

Place some <Spring> components using render props in its children with TypeScript.

Expected Behaviour

The render prop in children of <Spring> is inferred to some object reflecting the component's from and to props' structure.

Link to repo

https://codesandbox.io/s/clever-jennings-wo8jet?file=/src/App.tsx

joshuaellis commented 2 years ago

Introduced between 9.5.2-9.5.3, probably due to this commit – https://github.com/pmndrs/react-spring/commit/2725fc328b4cec9b726e5e04e912dfaa9359750a

astj commented 2 years ago

@joshuaellis Thank you for response. So, is it safe to downcast this any to expected structure manually as a workaround? (In other words, is it just a type-inference problem and actual js implementation is not changed?)

joshuaellis commented 2 years ago

It'll just be a type-inference problem.

Out of curiosity, how come you're still using the Component signatures of react-spring as opposed to hooks?

astj commented 2 years ago

Generally we use hooks, but according to commit logs in our repo we've changed few hooks to <Spring> some months ago. I believe there was a reason, but unfortunately we can't remember it anymore 😢