Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript] Type inference fails when useTransition styles are set via functions #1483

Closed
hsunpei opened this issue May 1, 2021 · 5 comments
Labels
area: typescript Typescript issues
Milestone

Comments

@hsunpei
Copy link

hsunpei commented May 1, 2021

🐛 Bug Report

I was trying to make an animated tree diagram using SVG and visx by modifying the example.

👉 Link to Codesandbox: https://codesandbox.io/s/tree-diagram-visx-t3q2d?file=/src/AnimatedLines.tsx

In 9.0.0-rc.3 the type inference of useTransition worked pretty well, the styles can be properly inferred as:

{
    sx: number;
    sy: number;
    tx: number;
    ty: number;
}

However, after upgrading to the newer version of react-spring, the styles is inferred as {}.

Does anyone have an idea about the cause of this problem?

To Reproduce

Steps to reproduce the behavior:
Open AnimatedLines.tsx: https://codesandbox.io/s/tree-diagram-visx-t3q2d?file=/src/AnimatedLines.tsx
In line 44, there are Typescript errors because the styles cannot be properly inferred.

While downgrading to 9.0.0-rc.3 solve this issue.

Expected behavior

In 9.0.0-rc.3 transition is inferred correctly:
Screen Shot 2021-05-01 at 3 58 24 PM

After the upgrade, transition is inferred as TransitionFn<HierarchyPointLink<T>, {}>.

Link to repro (highly encouraged)

https://codesandbox.io/s/tree-diagram-visx-t3q2d?file=/src/AnimatedLines.tsx

Environment

  • react-spring v9.1.2
  • react v17.0.1
@joshuaellis
Copy link
Member

Your example is very noisy, firstly have you checked the docs for transition? I know there were huge changes from rc3 to stable.

Secondly, can you reduce your sandbox down to the essence of the bug please?

@hsunpei
Copy link
Author

hsunpei commented May 1, 2021

Hi @joshuaellis,
Thanks so much for your prompt reply!

I tried to reproduce the issue by modifying the official example, and found that if I am not using CSS attributes as the return value such as sx in from, enter, update, and leave functions, the type inference might not be able to work as before (9.0.0-rc.3):

https://codesandbox.io/s/react-spring-transition-example-q649f?file=/src/App.tsx

Is this the intended change to restrict the use of none CSS attributes after the upgrade to the v9 official release?

@joshuaellis
Copy link
Member

No, i don't think it's because they're a CSS value, i think it's because you're using a function to set the vals.

So if you just do:

enter: { xy: 0, ty: 100 }

It will know the types exist, but it clearly doesn't if they're the ReturnValue of a function. If you're interested in solving the issue – that's it.

@joshuaellis joshuaellis changed the title [Typescript] Type inference error of useTransition after upgrading to 9.1.2 [Typescript] Type inference fails when useTransition styles are set via functions May 2, 2021
@joshuaellis joshuaellis added the area: typescript Typescript issues label May 2, 2021
@joshuaellis joshuaellis added this to the v9.X.X milestone May 2, 2021
@joshuaellis joshuaellis modified the milestones: v9.X.X, v9.3.0 May 13, 2021
@joshuaellis
Copy link
Member

i've released a beta v9.2.5-beta.0, let me know if this resolves your issue 💪🏼

@hsunpei
Copy link
Author

hsunpei commented Oct 2, 2021

Hi @joshuaellis,
Thanks so much for the fix! The issue no longer exists with v9.2.5-beta.0 🙂

@hsunpei hsunpei closed this as completed Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: typescript Typescript issues
Projects
None yet
Development

No branches or pull requests

2 participants