Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript and component selectors #685

Closed
kptlronyttcna opened this issue May 28, 2018 · 2 comments
Closed

Typescript and component selectors #685

kptlronyttcna opened this issue May 28, 2018 · 2 comments

Comments

@kptlronyttcna
Copy link

kptlronyttcna commented May 28, 2018

  • emotion version: 9.1.3
  • react version: 16

Consider Wrapper defined like this:

interface IconProps {
  name: string
  className?: string
}
const ReactIcon : React.StatelessComponent<IconProps> = .... // some react component
const Icon = styled(ReactIcon)``

const Wrapper = styled.div`
  ${Icon} {
      color: black;
  }
`

Then this component will not compile:

<Wrapper>
  <Icon name="menu" />
</Wrapper>

Typescript error:

TS2322: Type '{ children: Element[]; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<IconProps & { children?: ReactNode; } & ...'.
  Type '{ children: Element[]; }' is not assignable to type 'Readonly<IconProps & { children?: ReactNode; } & ClassAttributes<HTMLDivElement> & HTMLAttributes...'.
    Property 'name' is missing in type '{ children: Element[]; }'.
@kptlronyttcna
Copy link
Author

Hmm. This one works

const Wrapper = styled.div`
  ${Icon as any} {
      color: black;
  }
`

@Ailrun
Copy link
Member

Ailrun commented Jun 8, 2018

Close this in favor of #675.

@Ailrun Ailrun closed this as completed Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants