Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

No support for typescript syntax #22

Closed
vincaslt opened this issue May 2, 2017 · 4 comments
Closed

No support for typescript syntax #22

vincaslt opened this issue May 2, 2017 · 4 comments

Comments

@vincaslt
Copy link

vincaslt commented May 2, 2017

Specifying proptypes with typescript syntax breaks highlighting:

const StyledHeader = styled<Props>(Header)`
  position: fixed
  width: 100%
  background-color: ${({ theme }: Props) => theme.colors.secondary}
  height: 50px
`

All of the rules are highlighted with string highlighting.

@CBainx
Copy link

CBainx commented May 8, 2017

As far as I know, you can't specify the props that way. (Reference: microsoft/TypeScript#11947)
If Header is a regular component, you could remove <Props> and you'd still get type checking. If it's a stateless component you have to do something like whats in the docs: https://github.com/styled-components/styled-components/blob/master/docs/typescript-support.md

You can however remove <Props> and just replace the following line:
background-color: ${(props: Props) => props.theme.colors.secondary}

@julienp
Copy link
Collaborator

julienp commented May 25, 2017

Can this issue be closed or can someone confirm that we do need to support something like styled<Type>?

@clayne11
Copy link

clayne11 commented Jun 8, 2017

We definitely need to support this. It's 100% allowed. I use it with stateless components as so:

interface RootProps {
  label: React.ReactNode,
}

const Root = styled<RootProps>('div')`
  height: ${(props) => props.label ? 72 : 48}px;
`

Without specifying the props that way it TypeScript will complain about props.label.

@misantronic
Copy link

+1

This could be pretty easily solved by changing the regex-statement in line 7:
https://github.com/styled-components/vscode-styled-components/blob/master/syntaxes/styled-components.json

I will try to make it work and add a pull-request

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants