gpt4 book ai didi

reactjs - JSX 的 Typescript 集类型注解

转载 作者:搜寻专家 更新时间:2023-10-30 21:33:30 25 4
gpt4 key购买 nike

如何设置 JSX 的类型注解?

我想检查收到的 Prop 是否为 JSX 类型,而不是任何其他类型。

这是我的界面:

interface ITextEditorProps{
value: any
}

// Component
<TextEditor value={<div><h1>Hello World</h1></div>} />

最佳答案

有一个类型 JSX.Element更广泛的方法或直接使用 React.ReactElement<type>

interface ITextEditorProps {
value: JSX.Element // React.ReactElement<type> also possible
}

关于reactjs - JSX 的 Typescript 集类型注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55727269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com