TypeScript 和 React - 子类型?

新手上路,请多包涵

我有一个非常简单的功能组件如下:

 import * as React from 'react';

export interface AuxProps  {
    children: React.ReactNode
 }

const aux = (props: AuxProps) => props.children;

export default aux;

还有另一个组件:

 import * as React from "react";

export interface LayoutProps  {
   children: React.ReactNode
}

const layout = (props: LayoutProps) => (
    <Aux>
        <div>Toolbar, SideDrawer, Backdrop</div>
        <main>
            {props.children}
        </main>
    <Aux/>
);

export default layout;

我不断收到以下错误:

[ts] JSX 元素类型“ReactNode”不是 JSX 元素的构造函数。类型“未定义”不可分配给类型“ElementClass”。 [2605]

如何正确输入?

原文由 Asool 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 540
1 个回答

只是 children: React.ReactNode

原文由 Ridd 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进