Definitelytyped: [styled-components] not working with older versions of hoist-non-react-statics

Created on 5 Jun 2020  路  3Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/styled-components package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @Igorbek @Igmat @LavaToaster @Jessidhia @JKillian @eps1lon @flavordaaave @wagerfield @Lazyuki @mgoszcz2 @danilofuchs

I have a dependency that installs hoist-non-react-statics@2 which causes errors for the definitions in @types/styled-components when using v4.4.1 or higher. This issue can be replicated by manually installing an older version: npm i hoist-non-react-statics@2.

My current solution is to add @types/hoist-non-react-statics@3 to my own package so that @types/styled-components imports the correct version. Perhaps the dependency for @types/hoist-non-react-statics should be "^3.0.0" instead of "*"?

Most helpful comment

@gorazu Hey, I noticed that only adding the type declarations would not always fix the issue. Try also adding the package itself npm i --save-dev hoist-non-react-statics@3

All 3 comments

Thank you @marwankhalili , it seems that I have the same issue, whenever I use styled-components styled method I loose any typings on my components, as I am migrating an app to typescript it is really frustrating.

I also have several packages that use hoist-non-react-statics@2 and adding a newer version of @types/hoist-non-react-statics didn't fix the issue.

Any help would be appreciated !

@gorazu Hey, I noticed that only adding the type declarations would not always fix the issue. Try also adding the package itself npm i --save-dev hoist-non-react-statics@3

It worked when installing the package and the types, thank you very much @marwankhalili !

Was this page helpful?
0 / 5 - 0 ratings