Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 接口不能同时扩展类型锚和按钮_Reactjs_Typescript - Fatal编程技术网

Reactjs 接口不能同时扩展类型锚和按钮

Reactjs 接口不能同时扩展类型锚和按钮,reactjs,typescript,Reactjs,Typescript,我为React按钮(可以是锚或按钮)提供了以下界面: type buttonypes=htmlanchoreElement | HTMLButtonElement; 界面按钮按钮 扩展React.AnchorHtmlatAttributes,React.ButtonHtmlatAttributes{ 类名?:字符串; 种类:'默认'|'主要'|'次要'|'第三'; 禁用?:布尔值; 图标?:React.ReactElement; trailingIcon?:布尔值; i非线性?:布尔型; 全宽?

我为React按钮(可以是锚或按钮)提供了以下界面:

type buttonypes=htmlanchoreElement | HTMLButtonElement;
界面按钮按钮
扩展React.AnchorHtmlatAttributes,React.ButtonHtmlatAttributes{
类名?:字符串;
种类:'默认'|'主要'|'次要'|'第三';
禁用?:布尔值;
图标?:React.ReactElement;
trailingIcon?:布尔值;
i非线性?:布尔型;
全宽?:布尔值;
轮廓?:布尔;
大小?:“小”|“大”;
href?:字符串;
子节点?:React.ReactNode;
}
但是我得到一个错误,我不能同时扩展
React.AnchorHtmlatAttributes
React.ButtonHtmlatAttributes
,因为类型的命名属性“type”不相同

然而,这是受到材料设计如何制作按钮的启发:


所以我不确定为什么我不能继承这两个,但他们(MDC)已经能够继承了?我是否缺少允许此行为的内容(语法或类型包)?

要解决此问题,我必须通过添加以下内容覆盖type属性:

type?:“提交”|“重置”|“按钮”进入我的
按钮操作
界面

我还必须改变按钮的制作方式:

if (href) {
    return (
        <a {...(props as React.HTMLProps<HTMLAnchorElement>)} href={href}>{btnContent}</a>
    )
}

return (
    <button {...(props as React.HTMLProps<HTMLButtonElement>)}>{btnContent}</button>
);
if(href){
返回(
)
}
返回(
{btnContent}
);
致:

if(href){
返回(
)
}
返回(
{btnContent}
);

他们正在扩展
主播htmlattributes
而不是
htmlanchoreElement
。虽然我不知道主播的样子,但这可能不是你的情况。我也在扩展主播的内容……哦,对不起。我以为你说的是
buttonypes
if (href) {
    return (
        <a {...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)} href={href}>{btnContent}</a>
    )
}

return (
    <button {...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}>{btnContent}</button>
);