Skip to content

Using CSS prop with react-spring in Typescript causes "Type instantiation is excessively deep and possibly infinite" compilation error #3496

Closed

Description

@matt-winfield

Referencing the css prop types from styled-components anywhere in a project causes a "Type instantiation is excessively deep and possibly infinite" compilation error when creating a react-spring animated component.

I have tried several of the different methods for refferencing the types for styled-components listed in this issue: DefinitelyTyped/DefinitelyTyped#31245 and all of them have the same error.

Also raised an issue for this in the react-spring repo as it's not clear from which library this needs to be fixed in. pmndrs/react-spring#1515

Note that the css prop doesn't have to be used anywhere for this issue to occur, it's only the type reference that's needed to conflict with react-spring.

Environment

System:

  • OS: Windows 10 10.0.19041
  • CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
  • Memory: 17.02 GB / 31.90 GB

Binaries:

  • Node: 14.15.4 - C:\Program Files\nodejs\node.EXE
  • Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
  • npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD

npmPackages:

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

Steps to Reproduce

  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 react-spring animated compenent (e.g. animated.div) in App component

Expected behavior

<animated.div></animated.div> should have no compilation errors

Actual behaviour

"Type instantiation is excessively deep and possibly infinite" compilation error

image

Link to repro

CodeSandbox repro

Activity

  1. kitten commented on Aug 9, 2021

    @kitten
    Member

    Let's keep this to the definitely-typed repo for now, since we don't maintain the typings in here. In other words, nothing we would change or do here, can influence or faciliate the resolution of this issue 😅

    The styled-components typings are currently actually not maintained in the mainline repository but are located in DefinitelyTyped. Hence, we unfortunately don't maintain them directly here, but they're maintained by different people, until we settle on whether we can release a Typescript rewrite with better typings baked in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions