【发布时间】:2022-07-06 14:45:25
【问题描述】:
我升级到 React 18 并且编译正常。今天,似乎每个使用子组件的组件都在抛出错误。 Property 'children' does not exist on type 'IPageProps'.
在儿童道具自动包含在FC 界面中之前。现在看来我必须手动添加children: ReactNode。 What is the correct typescript type for react children?
这是 React 18 更新的一部分,还是我的环境搞砸了?
package.json
"react": "^18.0.0",
"react-dom": "^18.0.0",
"next": "12.1.4",
"@types/react": "18.0.0",
"@types/react-dom": "18.0.0",
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"alwaysStrict": true,
"sourceMap": true,
"incremental": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
【问题讨论】:
-
我遇到了同样的问题。看起来,无论出于何种原因,他们在 Component 类上删除了
children
标签: javascript reactjs typescript