0
我想什么做的是沿着此线的东西:是否可以有效地扩展HTMLProps类型?
MyButton.jsx
type Props = { foo?: 'x' | 'y' | 'z'; ...HTMLProps<HTMLButtonElement> };
const MyButton = ({ foo = 'y', ...props }: Props) => {
return (
<button class={foo} {...props}/>
)
}
Application.jsx
...
render() {
<MyButton
onClick={() => this.setState({ bar: true })}
foo="z" />
}
...
不幸的是,这个语法复制了一个类型的所有内容或接口到另一个不存在。
对HTML属性的FlowType支持非常有用,我不想将它们全部复制到我自己的道具定义中,以便它们可以传递给子元素 - 相反,我只是想添加一些把我自己的财产放在这个清单上,把它们摘下来,把余下的东西送到这个链条上。