Home > Software design >  interface does not work for type const material ui BoxProps['sx']
interface does not work for type const material ui BoxProps['sx']

Time:08-11

interface does not work for type const material ui. how to register an interface for sx here? I did this but it gives me an error

 import { BoxProps } from '@mui/material';
    
    interface Props {
    sx: BoxProps['sx'];
    }
    
    export const test: Props = {
    mb: 3,
    };

CodePudding user response:

The interface is defining that the object should have an sx property.

So in order to comply with the interface you can define the test like this:

export const test: Props = {
  sx: { mb: 3 },
};

OR change the interface:

type Props2 = BoxProps['sx']

TS Playground

  • Related