我在用
react-bootstrap
包,用React编写,用TypeScript编写。
我有一个包裹
Button
组件来自
反应引导
,我想接受所有的道具
按钮
接受(因此,接受底层HTML
button
元素也接受,如
style
),添加到这个新组件中,以便我可以将它们传递给
按钮
.
简单的例子,还没有指定类型:
import { Button } from 'react-bootstrap';
function WrapperButton(props) {
const { children } = props;
return <Button {...props}>{children}</Button>;
}
In
react-bootstrap/Button.d.ts
,
<Button>
声明如下:
declare class Button<
As extends React.ElementType = 'button'
> extends BsPrefixComponent<As, ButtonProps> {}
但如果我设定
props: BsPrefixComponent<'button', ButtonProps>
那么它就不接受以下属性
风格
和
children
.
对于这种情况,我可以使用更合适的类型吗?