Styled-components errors with React 16 + Typescript
See original GitHub issueVersion
babel-preset-react@6.24.1 react@16.0.0 styled-components@2.2.1 typescript@2.5.3
Reproduction
Steps to reproduce
- Upgrade to React 16
- 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:
- Created 6 years ago
- Comments:10 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
rm -rf node_modules && yarn cache clean && yarn