I’m using styled-system and one key of the library is to use the shorthand props to allow easy and fast theming.
I’ve simplified my component but here is the interesting part:
import React from 'react'
import styled from 'styled-components'
import { color, ColorProps } from 'styled-system'
const StyledDiv = styled('div')<ColorProps>`
${color}
`
const Text = ({ color }: ColorProps) => {
return <StyledDiv color={color} />
}
I have an error on the color
prop which says:
Type ‘string | (string | null)[] | undefined’ is not assignable to
type ‘string | (string & (string | null)[]) | undefined’.
I think that’s because styled-system
use the same naming as the native HTML attribute color
and it conflicts.
How do I solve this?
Instead of using
ColorProps
, try usingcolor: CSS.ColorProperty
(`import * as CSS from ‘csstype’); Here is a gist showing how I’m creating some a typed “Box” primitive with typescript/styled-system: https://gist.github.com/chiplay/d10435c0962ec62906319e12790104d1Good luck!
color
seems to be declared in react’s declaration file underHTMLAttributes
– it’s not exported.I had to work around this by creating a custom prop
Example is using
@emotion/styled
but also works withstyled-components
Building on Chris’ answer, and using the latest docs on on custom props.
EDIT: updating to styled-components ^5.0.0 fixes this
https://github.com/styled-components/styled-components/blob/master/CHANGELOG.md#v500—2020-01-13
What I did was to use Typescript cast capabilities and keep styled-system logic intact. e.g.:
Just to add to xuanlopez‘ answer – not sure what issue the 5.0.0 release specifically resolves – but using
$color
as the renamed prop rather thantextColor
designates it as a transient prop in styled components so as a prop it won’t appear in the rendered DOM.finasteride prostate cancer – generic propecia how much does propecia cost per month
generic tadalafil 20mg – http://xtadalafilp.com/ tadalafil generique
Nvnssd – provigil for adhd Zwcdkm qsregu
Yhcnak – fluconazole generic cost Kcmjka istiud
Pcnrup – essay writer for you Osmcws fuxqzr
Ucdprq – viagra pills online canada Gxvjgd fgzdfl
Fmorro – college essay assignment Celjil nfbqjb
Etbisr – finasteride generic india Lsdbgs qczhwy
Tqmlys – viagra feminino farmacia preГ§o Pcqyvv iyswjf
Fdfweq – does generic finasteride work as well as propecia Ybafdb spjywv
Gkcrws – outline apa writing research paper Ofyppt exdfoa
Bghqty – precio sildenafil walmart Ljandj htneyp
Qogsss – help me on my homework Lcylaz pdnjpi
Aawjqj – furosemidelasixx.com Ypqviz gritwu
Vruxoz – vardenafil tablets Miwxro eemnbe
best online dating sites
local personals