我正在使用Typescript在我的项目(我想在以后的项目中安装的自定义库)中使用Material-UI。我正在尝试导入库中的所有组件,并使用前缀(例如MUI[NameOfTheComponent]
之类的文件重新导出)。
在codeandbox中进行了修改,我可以使用重新导出的组件。
在我的项目中做同样的事情,我遇到了一个错误"Module xxx has no exported member MUIButton"
。
这是我的 package.json
:
{
"@material-ui/core": "^4.2.1",
"typescript": "^3.3.3"
}
这是我的代码,用于重命名/导出组件
在我的 MaterialUI.ts
中:
import * as MaterialUICore from '@material-ui/core';
module.exports = Object.entries(MaterialUICore).reduce((accu, [key, value]) => {
if (typeof value === 'function') {
return { ...accu, [`MUI${key}`]: value };
}
return {
...accu,
[`MUI${key}`]: { ...value, displayName: `MUI${key}` },
};
}, {});
在 index.ts
中:
export * from './MaterialUI';
问题:如何导出没有此错误的组件。