question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript complains when the css prop is passed back into the css prop using array composition

See original GitHub issue

I’m attempting to compose styles so that any css prop styles passed into my component are merged back into the inner styles (and take precedence)

The problem is that the TS compiler complains when i attempt to pipe the the received css prop back into the prop.

For example:

export type PProps = React.HTMLAttributes<HTMLParagraphElement>

export const P = (props: PProps) => (
    <p
        css={theme => [css`font-family: ${theme.font.secondary};`, props.css]} // <-- typescript complains
        {...props}
    />
)

Is this expected / or is there a better way to achieve this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
sami616commented, Apr 16, 2020
2reactions
Andaristcommented, Apr 16, 2020

Could you prepare a runnable repro case so I could take a look?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use styled-component CSS props with Typescript
As far as I understand your code, you don't need to use any libraries. Here is the working example, where colors in the...
Read more >
TS Playground - An online editor for exploring TypeScript and ...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Read more >
Minimal TypeScript Crash Course For React
This page aims at getting you up to speed quickly without overwhelming you with all the details. You'll get a rather minimal introduction...
Read more >
Generically Typed Vue Components with Composition API
In a nutshell, we need a way to pass down the generic type information and replace the value prop type with it.
Read more >
React hooks (v17.0.3) and Redux handbook using TypeScript ...
render props: Passing functions down the component hierarchy as via ... At a high level there are 2 strategies to consider when using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found