callstack / callstack/linaria

Conditional CSS with styled tag

Open
#409 8 comments 22 reactions 0 assignees View on GitHub
cat: extend syntax ✍ core team 🧬 feature: proposal 💬 platform: react 🛠️
Dominant language
TypeScript
Stars
12.4k
Forks
413
PR merge metrics
No merged PRs in 30d

Description

## Ask your Question

Is it possible to do something like the following?

```
const TopLevelList = styled.ul<{ dark?: boolean }>`
border-top: 1px solid ${BrandColors.BORDER};
margin-top: 0;

${props => props.dark && ({
color: 'black',
})}
`;
```

Typescript is giving the following error:

```
Argument of type '(props: { dark?: boolean | undefined; }) => false | { color: string; } | undefined' is not assignable to parameter of type 'string | number | CSSProperties | ((props: { dark?: boolean | undefined; }) => TLength)'.
Type '(props: { dark?: boolean | undefined; }) => false | { color: string; } | undefined' is not assignable to type '(props: { dark?: boolean | undefined; }) => TLength'.
Type 'false | { color: string; } | undefined' is not assignable to type 'TLength'.
Type 'undefined' is not assignable to type 'TLength'.ts(2345)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.