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

Component created with styled doesn't contain the component prop in TS #44192

Closed
vitorpdasilva opened this issue Oct 22, 2024 · 4 comments
Closed
Assignees

Comments

@vitorpdasilva
Copy link

vitorpdasilva commented Oct 22, 2024

Steps to reproduce

Link to live example: (required)

Steps:

  1. Have a component <List component="nav">
  2. switch to a styled component, for example
import {  List,  styled } from '@mui/material';

const StyledList = styled(List)({
  display: 'flex',
  flexDirection: 'column',
  width: 240,
});

<StyledList component="nav">
  1. An error will pop up.
Type '{ children: Element[]; component: string; }' is not assignable to type 'IntrinsicAttributes & ListOwnProps & CommonProps & Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & { ...; }, "classes" | ... 6 more ... | "subheader"> & MUIStyledCommonProps<...>'.
  Property 'component' does not exist on type 'IntrinsicAttributes & ListOwnProps & CommonProps & Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & { ...; }, "classes" | ... 6 more ... | "subheader"> & MUIStyledCommonProps<...>'.

Current behavior

It throws the error

Type '{ children: Element[]; component: string; }' is not assignable to type 'IntrinsicAttributes & ListOwnProps & CommonProps & Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & { ...; }, "classes" | ... 6 more ... | "subheader"> & MUIStyledCommonProps<...>'.
  Property 'component' does not exist on type 'IntrinsicAttributes & ListOwnProps & CommonProps & Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "ref"> & { ...; }, "classes" | ... 6 more ... | "subheader"> & MUIStyledCommonProps<...>'.

Expected behavior

dont throw any error.

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  @emotion/react: ^11.13.3 => 11.13.3 
    @emotion/styled: ^11.13.0 => 11.13.0 
    @mui/base:  5.0.0-beta.58 
    @mui/core-downloads-tracker:  6.1.3 
    @mui/icons-material: ^6.1.3 => 6.1.3 
    @mui/lab: 6.0.0-beta.11 => 6.0.0-beta.11 
    @mui/material: ^6.1.3 => 6.1.3 
    @mui/private-theming:  6.1.3 
    @mui/styled-engine:  6.1.3 
    @mui/styles: ^6.1.3 => 6.1.3 
    @mui/system:  6.1.3 
    @mui/types:  7.2.18 
    @mui/utils: ^6.1.3 => 6.1.3 
    @mui/x-date-pickers: ^6.18.6 => 6.20.2 
    @types/react: ^18.2.0 => 18.3.11 
    react: ^18.3.0 => 18.3.1 
    react-dom: ^18.2.0 => 18.3.1 
    typescript: ^5.6.3 => 5.6.3 

Search keywords: list component v6

@vitorpdasilva vitorpdasilva added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 22, 2024
@aarongarciah
Copy link
Member

aarongarciah commented Oct 23, 2024

Thanks for reporting @vitorpdasilva. Here's a reproduction https://codesandbox.io/p/sandbox/sad-faraday-ghd8xh?file=/src/Demo.tsx

The JS implementation works, but the component prop is missing in the TS counterpart.

Until we solve the issue, using the as prop should be equivalent:

<StyledList as="nav">

edit: the as prop is not equivalent.

@aarongarciah
Copy link
Member

@vitorpdasilva sorry for my last comment, the as prop is not equivalent. We'll take a look at the issue.

@aarongarciah aarongarciah changed the title Styled function used with List component prop throwing error after migration to v6 Component created with styled doesn't contain the component prop in TS Oct 23, 2024
@mnajdova
Copy link
Member

This is not a new issue, the solution is documented in https://mui.com/material-ui/guides/composition/#with-typescript. It's either this or you cast the newly created component with as typeof Typography (or any other Material UI component). This is likely a duplicate of: #29875

@aarongarciah
Copy link
Member

Thanks @mnajdova. Closing as duplicate of #29875

@aarongarciah aarongarciah closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@aarongarciah aarongarciah removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 23, 2024
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

4 participants