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

Add StyledComponent to allowed Interpolation types #635

Merged
merged 2 commits into from
May 15, 2018
Merged

Add StyledComponent to allowed Interpolation types #635

merged 2 commits into from
May 15, 2018

Conversation

mvestergaard
Copy link
Contributor

This fixes an error when referencing another StyledComponent from within
a template interpolation string

Fixes #625

@mvestergaard
Copy link
Contributor Author

I think I was a little too quick in assuming this fix works. This seems to cause props to have implicit any type in other scenarios. 😟

@mvestergaard
Copy link
Contributor Author

I took a different approach.

I added a simple "placeholder" interface called ComponentRef that StyledComponent extends, and use that as a valid Interpolation value.

This seems to work, and does not break existing typings.

This fixes an error when referencing another StyledComponent from within
a template interpolation string

Fixes #625
@pluma
Copy link

pluma commented May 3, 2018

Is there anything missing from this PR to get it merged?

@mvestergaard
Copy link
Contributor Author

A "problem" with this change, is that this will be allowed by the typing:

const NotStyled: React.SFC = () => <div />;

const Parent = styled.div`
  ${NotStyled} {
    color: green;
  }
`;

However personally I would rather that the typing allowed intended behavior, without having to use an escape hatch, than catching unintended usage.

@tkh44
Copy link
Member

tkh44 commented May 3, 2018

LGTM, but I'd rather have someone more confident in TS confirm to merge.

@tkh44 tkh44 merged commit 8f7c09a into emotion-js:master May 15, 2018
@pluma
Copy link

pluma commented May 15, 2018

Awesome! 🎉

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

Successfully merging this pull request may close these issues.

Typing of reference to other component seems broken
4 participants