Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
What is the type of a styled-component's argument(s)?

Using typescript and react here.

  1. Getting my variable

const dib = 'display: inline-block;'

  1. Creating a dumb component

export const FaGit = () => <i className="fa-brands fa-github"></i>

  1. Extending this dumb component with dib styles

export const GitIcon = styled(FaGit)(dib)

  1. At this point im getting errs
 TS2769: No overload matches this call.
  Overload 1 of 3, '(first: TemplateStringsArray): StyledComponent<() => Element, any, {}, never>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'TemplateStringsArray'.
  Overload 2 of 3, '(first: TemplateStringsArray | CSSObject | InterpolationFunction<ThemeProps<any>>, ...rest: Interpolation<ThemeProps<any>>[]): StyledComponent<...>', 
gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'TemplateStringsArray | CSSObject | InterpolationFunction<ThemeProps<any>>'.
  Overload 3 of 3, '(first: TemplateStringsArray | CSSObject | InterpolationFunction<ThemedStyledProps<{} & object, any>>, ...rest: Interpolation<...>[]): StyledComponent<...>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'TemplateStringsArray | CSSObject | InterpolationFunction<ThemedStyledProps<{} & object, any>>'.   

And so, what the type of dib should be, or how should it look like?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The styled(SomeComp)(...) function does not take a string. It takes a TemplateStringsArray. While this might look like a string, it's actually quite different.

See this playground example to see how such a tempate function might work:

function template(values: TemplateStringsArray, ...keys: any[]) {
  console.log(typeof values, values, keys)
}

const dib = 'display: inline-block;'  // <= string
const dib2 = `display: inline-block;` // <= still a string

template(dib)              // error... function does not take a string
template(dib2)             // still an error
template`hello ${1} world` // working! this isn't a string, it's a tagged template
template`${dib}`           // how you might get your string into a s-c template

As an aside, the styled-components documentation gives the following advice regarding the styling of React components:

If you use the styled(MyComponent) notation and MyComponent does not render the passed-in className prop, then no styles will be applied. To avoid this issue, make sure your component attaches the passed-in className to a DOM node

...so unless you pass down className:string property to the HTML element, your FaGit component will not respond to styled-components.

You could do it like this:

export const FaGit: React.FC<{className?: string}> = 
  ({className}) => <i className={`fa-brands fa-github ${className ?? ''}`}></i>

Putting this altogether, you should be able to:

export const GitIcon = styled(FaGit)`${dib}`;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!