question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styled-components errors with React 16 + Typescript

See original GitHub issue

Version

babel-preset-react@6.24.1 react@16.0.0 styled-components@2.2.1 typescript@2.5.3

Reproduction

Steps to reproduce

  1. Upgrade to React 16
  2. Create the following code
import React from 'react';
import styled from 'styled-components';

interface Props {
  className?: string;
  text: string;
}

class Text extends React.Component<Props, any> {
  public render() {
    const { className, text } = this.props;
    return <span className={className}>{text}</span>;
  }
}

export default styled(Text)`
  color: blue;
`;

Expected Behavior

Component compiles and works

Actual Behavior

Get the following error:

TS2605: JSX element type 'Component<ThemedOuterStyledProps<Props, any>, ComponentState>' is not a constructor function for JSX elements.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
probablyupcommented, Nov 15, 2018

Ask on DT. None of the core team uses typescript On Thu, Nov 15, 2018 at 6:07 AM Dan Ochiana notifications@github.com wrote:

getting close to 2019, still seeing this issue without a clear explanation on why it happens and an accepted solution for fixing it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/styled-components/styled-components/issues/1255#issuecomment-439018665, or mute the thread https://github.com/notifications/unsubscribe-auth/AAiy1o7pYTtkk_Nh1qzWdbOSVRfw3aCgks5uvVkbgaJpZM4P_oeH .

4reactions
mxstbrcommented, Oct 31, 2017

rm -rf node_modules && yarn cache clean && yarn

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript and styled-components gives error on import
Styled Components library does not ship with types. Instead, you'll need to install it from the Definitely Typed repository.
Read more >
FAQs - styled-components
In a React Native project using TypeScript, it is because you need to add @types/styled-components-react-native.
Read more >
styled-components - npm
styled -components is compatible with both React (for web) and React Native – meaning it's the perfect choice even for truly universal apps!...
Read more >
Styled-Components Ref Typescript error - CodeSandbox
Styled -Components Ref Typescript error. 0. Embed Fork Create Sandbox Sign in. Sandbox Info ... Environmentcreate-react-app ... @types/styled-components.
Read more >
Using styled-components with TypeScript - Bits and Pieces
Using Styled-components with React and React Native is great. ... with TypeScript and VS Code, getting code suggestions and errors when you ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found