export function FoodPost({ style, ...rest }: Props) { const [expanded, setExpanded] =…
- User
export function FoodPost({ style, ...rest }: Props) { const [expanded, setExpanded] = React.useState(false); return ( <Card style={style} sx={{ maxWidth: '33%' }}>
Style doesn't get assigned in react native here. [{ "resource": "/Users/eboschert/Desktop/Keepers/Programming/YikYakYum/components/FoodPost.tsx", "owner": "typescript", "code": "2769", "severity": 8, "message": "No overload matches this call.\n Overload 1 of 2, '(props: { component: ElementType<any, keyof IntrinsicElements>; } & CardOwnProps & CommonProps & Omit<any, "className" | ... 7 more ... | "raised">): Element | null', gave the following error.\n Type 'string | undefined' is not assignable to type 'CSSProperties | undefined'.\n Type 'string' has no properties in common with type 'Properties<string | number, string & {}>'.\n Overload 2 of 2, '(props: DefaultComponentProps<CardTypeMap<{}, "div">>): Element | null', gave the following error.\n Type 'string | undefined' is not assignable to type 'CSSProperties | undefined'.", "source": "ts", "startLineNumber": 42, "startColumn": 15, "endLineNumber": 42, "endColumn": 20, "relatedInformation": [ { "startLineNumber": 61, "startColumn": 3, "endLineNumber": 61, "endColumn": 8, "message": "The expected type comes from property 'style' which is declared here on type 'IntrinsicAttributes & { component: ElementType<any, keyof IntrinsicElements>; } & CardOwnProps & CommonProps & Omit<...>'", "resource": "/Users/eboschert/Desktop/Keepers/Programming/YikYakYum/node_modules/@mui/material/OverridableComponent.d.ts" }, { "startLineNumber": 61, "startColumn": 3, "endLineNumber": 61, "endColumn": 8, "message": "The expected type comes from property 'style' which is declared here on type 'IntrinsicAttributes & CardOwnProps & CommonProps & Omit<Omit<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "ref"> & { ...; }, "className" | ... 7 more ... | "raised">'", "resource": "/Users/eboschert/Desktop/Keepers/Programming/YikYakYum/node_modules/@mui/material/OverridableComponent.d.ts" } ] }]
- Assistant
The error message indicates that the
styleprop you are passing to theCardcomponent from MUI (Material-UI) does not match the expected type. Specifically, it looks likestylemight be a string or undefined, but theCardcomponent expects aCSSPropertiesobject.You should ensure that
styleis an object that matches theCSSPropertiestype. One way to handle this could be to provide a default style object if it's not defined or convert the provided style to the right type.Here's how you might adjust your code: