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.

[TS] StyledComponentClass does not have any construct or call signatures

See original GitHub issue

Hello. I’m trying to up a new project with typescript + styled-components, but I faced with a problem with prop types + jsx. I get this error: [ts] JSX element type 'Styled' does not have any construct or call signatures when I try to use a Component from styled.

type Props = {
  color: string,
};

const Styled = styled<Props>('div')`
  color: ${p => p.color};
`;

// later
render() {
  return (
    <Styled />  {/* [ts] JSX element type 'Styled' does not have any construct or call signatures */}
  ) ;
}

image

Styled type is StyledComponentClass<Props, any, Props> by inference as specified in styled typings.

image

But if I force the type as any it works ‘normally’, without error:

const Styled: any = styled<Props>('div')`
  color: ${p => p.color};
`;

image

But this way I’ll loss all the typing benefit, I think.

I tried put StatelessComponent<Props> instead of any, but unsuccessfully (I don’t know why, I’m new with TS)

image


How can I get around this situation?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

32reactions
renatoribcommented, Aug 10, 2017

Sorry, my bad. I forgot to install @types/react;

6reactions
tur-nrcommented, Aug 10, 2018

After much playing about I noticed that you have to enable Typescript support on VSCode. I had a fresh install of VSCode and after installing/enabling full support the Typingscript it worked.

image

Just click Typescript on the welcome screen and reload your editor. It’s funny cause Typescript syntax works out the box for VSCode, but only after I do this does it begin to work 🤔

Thanks again team.

❤️💅

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSX element type Elem does not have any construct or call ...
What you want is a function that takes a constructor for React. ... Type '(props: myProps) => Element' provides no match for the...
Read more >
JSX element type does not have any construct or call signatures
The error "JSX element type does not have any construct or call signatures" occurs when we try to pass an element or a...
Read more >
jsx element type 'component' does not have any construct or ...
Element" :: "JSX element type 'Component' does not have any construct or call signatures.ts(2604)". Currently, I have been looking to updates for both...
Read more >
Advanced Usage - styled-components
In the render tree all styled-components will have access to the provided theme, even when they are multiple levels deep. To illustrate this,...
Read more >
JSX element type X does not have any construct or call ...
JSX element type X does not have any construct or call signatures.ts(2604) ... I wanted to make a styled button with Material UI...
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