react-spring: "Type instantiation is excessively deep and possibly infinite" Typescript error when used with styled-components css prop
🐛 Bug Report
Using react-spring in conjunction with styled-components css prop in Typescript causes a “Type instantiation is excessively deep and possibly infinite” compilation error.
There are several ways to enable typescript support for the css prop from styled-components in typescript listed here: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31245 all of which cause this error.
To Reproduce
Steps to reproduce the behavior:
- Create a typescript react app with
npx create-react-app react-spring-css-prop-error --template typescript
- Add react-spring, styled-components and types:
yarn add react-spring styled-components @types/styled-components
- Add reference to css prop types in App.tsx:
/// <reference types="styled-components/cssprop" />
- Attempt to use animated compenent (e.g. animated.div) in App component
Expected behavior
<animated.div></animated.div>
should have no compilation errors
Link to repro
Environment
react-spring
v9.1.2react
v17.0.2styled-components
v5.3.0- '@types/styled-components` v5.1.9
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 11
- Comments: 22 (7 by maintainers)
For anybody else running into this issue with react-three-fiber (@looeee), I was having this issue because I hadn’t installed the types for threejs. Installing
@types/three
fixed everything. Here’s the relevant parts of mynpm ls
:@brancusi The work around I found currently was to just wrap the
animated.div
and reference that variable:const AnimatedDiv = styled(animated.div)``;
The following works for me.
After looking into #1784, we should also track this issue – https://github.com/microsoft/TypeScript/issues/34933
Leaving this here as its relevant to tracking the issue – https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31245