【发布时间】:2021-03-12 09:50:41
【问题描述】:
是否可以只允许特定组件作为子组件?例如:
function ListItem() {
return (
<div>
{this.props.children}
</div>
);
}
function OrderedList(children: <ListItem>[] /* won't work */ ) {
return (
<div>
{this.props.children}
</div>
);
}
【问题讨论】:
-
渲染时可以检查父组件类型吗?不确定这是否会在 preact 中起作用:stackoverflow.com/questions/55729582/…
-
谢谢大家。我并没有试图过滤掉其他类型的孩子,只是想让 Typescript 不编译。我也使用 Preact,而不是 React(如果不清楚的话)。
标签: typescript preact