【发布时间】:2023-04-06 21:29:01
【问题描述】:
我尝试在打字稿中动态检查反应子组件的类型。 以下代码运行良好,但似乎 typescript 不希望我解构孩子。
我收到打字稿错误:
TS2339: Property 'type' does not exist on type 'ReactNode'.
除了使用 // @ts-ignore 之外,我能做些什么来摆脱打字稿错误。
import * as React from 'react';
export interface AuxProps {
children: React.ReactNode[]
}
export const Message: React.FC<AuxProps> = ({
children,
}: AuxProps) => {
const test = children.filter(({ type }) => type === Test);
return (
<div>
{test}
<div/>
);
};
【问题讨论】:
标签: reactjs typescript children