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

[system] <Box component={Paper} square> throws unasignable type #16843

Closed
mayteio opened this issue Aug 1, 2019 · 4 comments · Fixed by #23686
Closed

[system] <Box component={Paper} square> throws unasignable type #16843

mayteio opened this issue Aug 1, 2019 · 4 comments · Fixed by #23686
Labels
bug 🐛 Something doesn't work component: Box The React component. package: system Specific to @mui/system typescript

Comments

@mayteio
Copy link

mayteio commented Aug 1, 2019

What it says on the tin - using typescript

  • [√] This is not a v0.x issue.
  • [√] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

Shouldn't complain when passing attributes component should accept

Current Behavior 😯

Does complain:

Type '{ children: Element; component: ComponentType<PaperProps>; square: true; className: string; }' is not assignable to type 'IntrinsicAttributes & BoxProps & { children?: ReactNode; }'.
  Property 'square' does not exist on type 'IntrinsicAttributes & BoxProps & { children?: ReactNode; }

Steps to Reproduce 🕹

https://codesandbox.io/s/kind-haslett-38ykt

Context 🔦

I want to leverage the awesome attributes Box gives me whilst using other components, for example;

<Box 
  component={Paper} 
  minHeight={320} // <Box /> prop
  square // <Paper /> prop
/>

From the typescript guide:

Not every component fully supports any component type you pass in. If you encounter a component that rejects its component props in TypeScript please open an issue. There is an ongoing effort to fix this by making component props generic.

Your Environment 🌎

Tech Version
Material-UI v5.0.0.alpha.13
React 1.6.8
Browser Chrome 75
TypeScript 3.5.3
@eps1lon eps1lon added component: Box The React component. typescript labels Aug 1, 2019
@hlynurl

This comment has been minimized.

@oliviertassinari oliviertassinari changed the title [Typescript] <Box component={Paper} square> throws unasignable type <Box component={Paper} square> throws unasignable type Dec 1, 2019
@oliviertassinari oliviertassinari changed the title <Box component={Paper} square> throws unasignable type [prop component] <Box component={Paper} square> throws unasignable type Dec 1, 2019
@MatthieuCoelho
Copy link

I confirm this issue sill exist.

@oliviertassinari oliviertassinari changed the title [prop component] <Box component={Paper} square> throws unasignable type [Box] <Box component={Paper} square> throws unasignable type Aug 22, 2020
@oliviertassinari oliviertassinari added package: system Specific to @mui/system bug 🐛 Something doesn't work labels Oct 20, 2020
@oliviertassinari oliviertassinari changed the title [Box] <Box component={Paper} square> throws unasignable type [system] <Box component={Paper} square> throws unasignable type Oct 20, 2020
@mnajdova
Copy link
Member

mnajdova commented Oct 21, 2020

For tracking, the issue exists with primitive component values as well. For example:

<Box
  component="img"
  src="https://tailwindcss.com/_next/static/media/erin-lindford.4804b52007ca82ebe9999d19c717b44d.jpg"
/>

First reported in #23053 (comment)

@cyrilchapon
Copy link

cyrilchapon commented Nov 21, 2020

Temporary workaround (here with a <form> component)

import { FunctionComponent, FormHTMLAttributes } from 'react'
import { Box, BoxProps } from '@material-ui/core'

type FormBoxProps = BoxProps & FormHTMLAttributes<HTMLFormElement>

export const FormBox: FunctionComponent<FormBoxProps> = (props) => (
  <Box {...props} component='form' />
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: Box The React component. package: system Specific to @mui/system typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants