【发布时间】:2021-02-19 16:09:59
【问题描述】:
这是我的布局:
export default function Layout(children:any) {
return (
<div className={`${styles.FixedBody} bg-gray-200`}>
<main className={styles.FixedMain}>
<LoginButton />
{ children }
</main>
<footer>
<FooterNavigation />
</footer>
</div>
)
}
还有我的应用:
function MyApp({ Component, pageProps }) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
)
}
为了使我的代码更简洁,我想将Layout(children:any) 设置为实际类型而不是任何类型,但是当我将其更改为Layout(children:ReactNode) 时,我在组件上的应用页面上收到此警告:
TS2322:类型 '{ 孩子:元素; }' 不可分配给类型 '内在属性 | (IntrinsicAttributes & 字符串) | (IntrinsicAttributes & number) | (IntrinsicAttributes & false) | (IntrinsicAttributes & true) | (内在属性 & 反应元素<...>) | (IntrinsicAttributes & ReactNodeArray) | (IntrinsicAttributes & ReactPortal)'。类型'{孩子:元素; }' 与类型“IntrinsicAttributes”没有共同的属性。
我应该将它设置为Layout(children:IntrinsicAttributes) { 是有道理的,但是当我这样做时,没有选项可以导入它。这应该设置成什么?
【问题讨论】:
-
应该设置为
ReactNode
标签: javascript reactjs typescript next.js