reactjs - Typescript / React:带有函数语句的类型中缺少属性'children'
问题描述
我有一个带孩子的 React 组件。
收到打字稿错误:
Property 'children' is missing in type ... but required in type 'FixedWidthLayout'
该组件的定义类似于函数语句。
export default function FixedWidthLayout { ... }
我不想写它喜欢和表达..
IE
export const FixedWidthLayout = () => {...}
因此,做类似...
const FixedWidthLayout: React.FC<Props> = () => {...}
..不是一种选择。
如何在带有函数语句的 Typescript 中使用它?
解决方案
你在哪里得到错误?
这应该只是工作:
import * as React from 'react';
interface Props {
children: React.Node;
}
export default function FixedWidthLayout(props: Props): JSX.Element {
/* ... */
}
<FixedWidthLayout>Hello</FixedWidthLayout>
推荐阅读
- terminal - 如何使用 goorm 终端创建文件
- sql - 存储过程返回默认值?
- angular - Angular Mat 选择 CompareWith ID 号,并发出整个对象
- java - 如何对依赖于 Maven 本地存储库的 Java 应用程序进行 Docker 化?
- sql - 插入有条件的表
- mysql - SQL如何从所有产品行中获取总和而不丢失视图中的每个产品行
- jquery - 如何使用ajax jquery将多个变量从视图传递到控制器
- kubernetes - 在 Prometheus 中的范围向量上进行标签替换
- java - Spring boot+tomcat 性能:服务器发送事件 vs websocket vs old-school REST
- javascript - 如何将包含左浮动元素的元素居中?