我升级到 React 18 并且编译得很好。如今,似乎每个使用子组件的组件都会抛出错误。Property 'children' does not exist on type 'IPageProps'.
在儿童道具自动包含在之前FC
界面。现在看来我必须手动添加children: ReactNode
. 对于反应儿童来说,正确的打字稿类型是什么? https://stackoverflow.com/questions/61236537/what-is-the-correct-typescript-type-for-react-children
这是 React 18 更新的一部分,还是我的环境出了问题?
包.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"]
}