-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: Assigning useTransition return value to a prop with type CSSProperties results in 'not assignable' error #1645
Comments
Please create a reproduction of the issue in a sandbox for review. |
I'm sorry, the link was wrong, I meant to link to this sandbox, which has the issue. |
This workaround helped me in the meantime const dropdown = useSpring({
opacity: (showMenu ? 1 : 0) as React.CSSProperties["opacity"],
pointerEvents: (showMenu
? "all"
: "none") as React.CSSProperties["pointerEvents"],
}) |
Should it be assignable to CSSProperties? You can resolve this by passing |
Thanks @joshuaellis that looks like an even-cleaner solution. |
@DamianPereira it'd be good to hear your thoughts on why you think it's an issue since we're not passing CSSProperties, we're passing SpringValues. |
@joshuaellis My 2 cents are that it should work without needing to cast or specify the type, which would mean returning the correct |
It does return SpringValues by default. The original issue is demonstrating that passing the props to another component means you have to cast it with SpringValues not CSSProperties. Unless you have a separate issue @DerekLoop? |
Hi @joshuaellis ! Thanks for the help. Maybe I'm just not understanding the types correctly. This example works in TypeScript: import { animated as a, SpringValues, useSpring } from "@react-spring/web"
const dropdown = useSpring({
opacity: (showMenu ? 1 : 0) as React.CSSProperties["opacity"],
pointerEvents: (showMenu
? "all"
: "none") as React.CSSProperties["pointerEvents"],
})
return (<a.div style={dropdown}>Content!</a.div>) This example gives an error: import { animated as a, SpringValues, useSpring } from "@react-spring/web"
const dropdown = useSpring({
opacity: showMenu ? 1 : 0,
pointerEvents: showMenu ? "all" : "none",
})
return (<a.div style={dropdown}>Content!</a.div>) This is the error:
This example also works without an error: import { animated as a, SpringValues, useSpring } from "@react-spring/web"
const dropdown = useSpring({
opacity: showMenu ? 1 : 0,
pointerEvents: showMenu ? "all" : "none",
}) as SpringValues<{ opacity: number; pointerEvents: "all" | "none" }>
return (<a.div style={dropdown}>Content!</a.div>) I'm just not sure why casting is necessary in either case 🎃😅 Though the SpringValues solution seems more correct. |
🐛 Bug Report
The returned value from useTransition styles is not assignable to a prop with type CSSProperties. The full error is:
This is probably related to #1102, it seems to keep happening under this scenario.
To Reproduce
Steps to reproduce the behavior:
Using this code (or any component which receives styles as a prop with type CSSProperties):
Expected behavior
There should be no compilation error since the type returned from useTransition should be compatible with CSSProperties.
Link to repro (highly encouraged)
Codesandbox link
Environment
react-spring
v9.2.4react
v17.0.3The text was updated successfully, but these errors were encountered: