React、Typescript和Material UI 4的编译问题



突然间,我的整个构建都崩溃了,无法构建。几天前,我用一个新的create-react应用程序构建重置了这个项目,它在一段时间内很好,然后在昨天-类似的问题有一个不同的错误:

Failed to compile.
TS2322: Type '{ children: Element; xsDown: true; }' is not assignable to type 'IntrinsicAttributes & HiddenProps'.
Property 'children' does not exist on type 'IntrinsicAttributes & HiddenProps'.
208 |                     {studentName(x)} <{x.student}>
209 |                 </Box>
> 210 |                 {!locked && <Hidden xsDown={true}><Box><RemoveButton deleteClickHandler={deleteClickHandler} x={x}/></Box></Hidden>}
|                              ^^^^^^
211 |                 {locked &&
212 |                 <Box>
213 |                     <Tooltip title="Locked"><Lock/></Tooltip>

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我已经剥离了一些我在小地方使用的库,我怀疑这些库会导致类型声明冲突,但是,我仍然遇到这个问题,在这一点上,我完全陷入了困境。

Package.json不是很复杂:

"name": "****Redacted****",
"version": "1.2.0",
"private": true,
"dependencies": {
"@date-io/date-fns": "^1.3.13",
"@fortawesome/fontawesome-common-types": "^6.1.1",
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@material-table/core": "^4.3.39",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.3",
"@sentry/react": "^6.19.6",
"@sentry/tracing": "^6.19.6",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.26.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/dateformat": "^5.0.0",
"@types/jest": "^27.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-router-dom": "^5.3.3",
"amazon-cognito-identity-js": "^5.2.8",
"amazon-cognito-identity-js-typescript": "^1.22.0",
"axios": "^0.26.1",
"dateformat": "^4.6.3",
"immutability-helper": "^3.1.1",
"react": "^18.0.0",
"react-dnd": "^14.0.5",
"react-dnd-html5-backend": "14.1.0",
"react-dnd-touch-backend": "14.1.0",
"react-dom": "^18.0.0",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.0",
"sass": "^1.49.11",
"typescript": "^4.6.3",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {}
}

我认为这是因为您已经更新到React 18(特别是"@types/react": "^18.0.0",(。

这个撤回请求说明了发生了什么变化。

由于问题源于材料Ui 4组件,因此您很可能需要执行以下操作之一:

  1. 升级到Mui5
  2. 降级至React 17
  3. 等待这个公关被合并,这似乎可以缓解你的问题

(此外,MUI4中的<Hidden/>确实使用children?: React.ReactNode;实现了子级,就像第一个链接提到的那样(

最新更新