Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'string' is not assignable to type 'BoxSizing' after styled update from 11.11.0 to 11.11.5 #3249

Open
maciejwitwicki opened this issue Aug 28, 2024 · 1 comment

Comments

@maciejwitwicki
Copy link

Current behavior:

React project has a compilation error when creating a div with boxSizing property using string value

 Types of property 'boxSizing' are incompatible.
              Type 'string' is not assignable to type 'BoxSizing | readonly NonNullable<BoxSizing | undefined>[] | readonly BoxSizing[] | undefined'.

To reproduce:

Create component that has boxSizing property defined with string 'content-box'

const CardInputContainer = styled.div(() => ({
  boxSizing: 'content-box',
}))

Expected behavior:

Project compiles

Environment information:

  • react version: 18.2.0
  • @emotion/react version: 11.11.3
@cofenster-micha
Copy link

I'm running into the same issues.

Environment information:

  • react version: 19.0.0
  • @emotion/react version: 11.14.0
  • @emotion/styled version: 11.14.0
import styled from '@emotion/styled';

export const FullSizeFlexContainer = styled('div')(() => ({
  display: 'flex',
  position: 'absolute',
  top: 0,
  right: 0,
  bottom: 0,
  left: 0,
}));

TypeScript error reported:

Types of property 'position' are incompatible.
    Type 'string' is not assignable to type 'Position | NonNullable<Position | undefined>[] | readonly Position[] | undefined'.ts(2769)

Adding as const fixes the issue, but I'd have to apply this change to hundreds of files.

import styled from '@emotion/styled';

export const FullSizeFlexContainer = styled('div')(() => ({
  display: 'flex',
  position: 'absolute' as const,
  top: 0,
  right: 0,
  bottom: 0,
  left: 0,
}));

or

import styled from '@emotion/styled';

export const FullSizeFlexContainer = styled('div')(
  () =>
    ({
      display: 'flex',
      position: 'absolute',
      top: 0,
      right: 0,
      bottom: 0,
      left: 0,
    }) as const
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants