I'm attempting to make a general Box react component on a new project. This will be the base of all other components. I'm using styled-system, emotion, and eventually theme-ui to handle themeing and styling of all my components.
My root Box component looks like this:
import styled from '@emotion/styled';
import {
compose,
space,
layout,
flexbox,
border,
position,
color,
SpaceProps,
ColorProps,
LayoutProps,
FlexboxProps,
BorderProps,
PositionProps,
} from 'styled-system';
export type BoxProps = SpaceProps &
ColorProps &
LayoutProps &
FlexboxProps &
BorderProps &
PositionProps;
export const Box = styled.div<BoxProps>(
{
boxSizing: 'border-box',
minWidth: 0,
},
compose(space, color, layout, flexbox, border, position)
);
I'm using styled functions along with their associated types from styled-system to create a Box component that accepts space, color, layout, flexbox, border, and position props.
The error I'm getting is happening only with the color prop. Once I remove that I don't get any errors.
The TS error is:
Type 'BoxProps' does not satisfy the constraint 'Pick<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "color">, "color">'.
Types of property 'color' are incompatible.
Type 'string | number | symbol | (string | number | symbol | null)[] | { [x: string]: string | number | symbol | undefined; [x: number]: string | number | symbol | undefined; } | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.ts(2344)
This seems to only be an issue when moving from styled-components to emotion, so I'm not sure if there's something I'm missing to properly utilize emotion's types?