Open delijah opened 7 months ago
The error in your linked sandbox is just because you added a non-optional prop and then didn't compose the prop.
Thx for your reply. What do you mean by "composing" the prop? Could you provide an example?
The thing is: when i use that component in the context of react, if i render that component, that prop must exist, but if i just want to use that styled component as a selector, why should i get notified about missing props? This is what i do not understand here.
@delijah he means this:
import { render } from "react-dom";
import styled, { createGlobalStyle } from "styled-components";
import React from "react";
const Wrapper = styled.section`
padding: 4em;
background: papayawhip;
`;
const Title = styled.h1<{ $color: string }>` // <= this is the mandatory custom prop
font-size: 1.5em;
text-align: center;
color: ${({ $color }) => $color};
`;
const GlobalStyle = createGlobalStyle<{$color: string}>` // <= it need to be propagated here
${Title} {
background: white;
}
`;
// Render these styled components like normal react components.
// They will pass on all props and work
// like normal react components – except they're styled!
const App = () => (
<Wrapper>
<GlobalStyle $color='blue' /> // <= and consumed here
<Title $color="palevioletred">
Hello World, this is my first styled component!
</Title>
</Wrapper>
);
render(<App />, document.getElementById("root"));
System:
Binaries:
npmPackages:
Reproduction
https://codesandbox.io/s/gifted-newton-q7fd9d
Steps to reproduce
When referencing a styled component within
createGlobalStyle
, i get a ts errorExpected Behavior
No type error
Actual Behavior
Type error