![](/img/trans.png)
[英]typescript compilation error - “Value of type … is not indexable by type …”
[英]Typescript: button type prop typescript compilation error
我有這個按鈕組件:
<button
className={internalClassName}
onClick={onClick ?? undefined}
disabled={disabled}
title={title}
style={style}
type={type}
{...event}
>
{icon && <Icon icon={icon} size={iconSize} color={iconColor} />}
{ text }
{ children }
</button>
類型在哪里
type ButtonTypes = 'button' | 'submit' | 'reset' | undefined;
問題是 typescript 編譯器抱怨 prop 類型:
鍵入'字符串 | undefined' 不可分配給類型 '"submit" | “重置” | “按鈕” | 不明確的'。 類型“字符串”不可分配給類型“提交”| “重置” | “按鈕” | 不明確的'。
為什么它說是一個字符串 | 當我將其聲明為“提交”時未定義 | '重置' | '按鈕' | 不明確的?
好的,更新:
似乎傳播道具事件是問題的原因
{...event}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.