修复了createTheme中自定义MuiDataGrid时的Typescript错误



我想在主题中自定义我的DataGridPro表(MUI组件)。然而,当我MuiDataGrid到组件对象时,我得到一个TS错误:

Object literal may only specify known properties, and 'MuiDataGrid' does not exist in type 'Components'.ts(2322)

Codesandbox:https://codesandbox.io/s/datagriddemo-material-demo-forked-vedcm

如何修复错误?我花了两个小时到处找,还是没有找到。

我在MUI github问题页面上得到了这个问题的答案:https://github.com/mui-org/material-ui-x/issues/1755#issuecomment-945650984

解决方案是像这样导入主题增强:

import type {} from '@mui/x-data-grid-pro/themeAugmentation';

如下所述:https://mui.com/components/data-grid/getting-started/#typescript