pmndrs / pmndrs/react-spring

"Type instantiation is excessively deep and possibly infinite" Typescript error when used with styled-components css prop

Open
#1,515 22 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: typescript status: won't fix
Dominant language
TypeScript
Stars
29.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

🐛 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.

image

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:

  1. Create a typescript react app with npx create-react-app react-spring-css-prop-error --template typescript
  2. Add react-spring, styled-components and types: yarn add react-spring styled-components @types/styled-components
  3. Add reference to css prop types in App.tsx: /// <reference types="styled-components/cssprop" />
  4. 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

CodeSandbox repro

Environment

  • react-spring v9.1.2
  • react v17.0.2
  • styled-components v5.3.0
  • '@types/styled-components` v5.1.9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction from the issue in the linked CodeSandbox or a TypeScript React app, focusing on App.tsx and the animated.div usage. Compare the behavior with react-spring v9.1.2, styled-components v5.3.0, and their listed type packages; done means the animated component compiles without the deep-instantiation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.