Skip to content

[bug]: Animated div typescript error regarding children prop #2358

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

Open
1 of 5 tasks
jeeheezy opened this issue Feb 21, 2025 · 7 comments · May be fixed by Capventis/react-spring#5
Open
1 of 5 tasks

[bug]: Animated div typescript error regarding children prop #2358

jeeheezy opened this issue Feb 21, 2025 · 7 comments · May be fixed by Capventis/react-spring#5
Labels
template: bug This issue might be a bug

Comments

@jeeheezy
Copy link

Which react-spring target are you using?

  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog

What version of react-spring are you using?

9.7.5

What's Wrong?

Animated tags don't seem to support children prop for TypeScript. This seems similar to issue #2332, but I'm not using Next 15/React 19, I am currently using Next 14.2.24 and React 18.3.1.

Image

The animated.div only has an SVG (made React component by SVGR) as a child. While I was able to get around the issue by using the animated function instead and passing a component in there (i.e. see second image, there are no typescript errors present there), I'm sure there would be situations where having animated.div take children would be preferable compared to defining a component separately.

Image

To Reproduce

Use an animated tag with children elements

Expected Behaviour

No Typescript issue

Link to repo

No public repo currently

@jeeheezy jeeheezy added the template: bug This issue might be a bug label Feb 21, 2025
@1940879828
Copy link

2025/2/25。I encountered the same bug
"next": "15.1.5",
"react": "^18.3.1",
"@react-spring/web": "^9.7.5",

<a.div style={springs}>
        <div>test</div>
 </a.div>

error

Property 'children' does not exist on type 'IntrinsicAttributes & AnimatedProps<{ style?: { accentColor?: AccentColor | undefined; alignContent?: AlignContent | undefined; alignItems?: AlignItems | undefined; ... 841 more ...; matrix3d?: readonly [...] | undefined; } | undefined; }> & { ...; }'.

@1940879828
Copy link

I have a temporary solution.
Patch the type file.

diff --git a/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts b/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
index f647f1b..a18ef5c 100644
--- a/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
+++ b/node_modules/@react-spring/web/dist/react-spring_web.modern.d.ts
@@ -24,7 +24,9 @@ type AnimatedComponent<T extends ElementType> = ForwardRefExoticComponent<Animat
 }>>;
 /** The props of an `animated()` component */
 type AnimatedProps<Props extends object> = {
-    [P in keyof Props]: P extends 'ref' | 'key' ? Props[P] : AnimatedProp<Props[P]>;
+    [P in keyof Props]: P extends 'ref' | 'key' | 'children' ? Props[P] : AnimatedProp<Props[P]>;
+} & {
+    children?: React.ReactNode;
 };
 type StyleProps = Merge<CSSProperties, TransformProps>;
 type StylePropKeys = keyof StyleProps;

This eliminates type errors, but I don't know if it will cause other type problems, so use caution

@Deftunk
Copy link

Deftunk commented Feb 26, 2025

Having the same issue here.
But I would not recommend your solution @1940879828. I cant agree with the modification of a node_module. Everytime you will npm or yarn the issue will be back.
I would more recommend to temporary override the type of animated with custom type by adding to a file custom.d.ts some code like bellow.

import reactSpring from "@react-spring/web";
declare module "@react-spring/web" {
  const animated = {
    children: React.ReactNode,
    ...reactSpring.animated,
  };
}

@flangham
Copy link

flangham commented Mar 6, 2025

Having same issue

@ta93imtk
Copy link

ta93imtk commented Mar 10, 2025

I haven't checked in previous version, but the workaround below has worked in the latest.

react 19.0.0 / @react-spring/web 9.7.5

export default function App() {
  const [open, toggle] = useState(false)
  const [ref, { width }] = useMeasure()
  const props = useSpring({ width: open ? width : 0 })

  // ↓workaround
  const AnimatedDivFill = animated("div")
  const AnimatedDivContent = animated("div")
  // ↑

  return (
    <div className={styles.container}>
      <div ref={ref} className={styles.main} onClick={() => toggle(!open)}>
        <AnimatedDivFill className={styles.fill} style={props} />
        <AnimatedDivContent className={styles.content}>{props.width.to(x => x.toFixed(0))}</AnimatedDivContent>
      </div>
    </div>
  )
}

@Deftunk
Copy link

Deftunk commented Mar 11, 2025

this is issue is only a type issue. Dont modify your code patterns for it. Just override the type like I did in my post above.
@joshuaellis Any resolution scheduled ?

liambickett added a commit to liambickett/react-spring-web-typefix that referenced this issue Mar 30, 2025
…ror (pmndrs#2358)

React 19 moved the JSX namespace from global scope to the React module. This updates type definitions to explicitly import the `JSX` type from 'react', resolving issues issues for consumers using React 19+.

Note: Backwards-compatible with React 18.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: bug This issue might be a bug
Projects
None yet
5 participants