今天看到张鑫旭推荐的 Lulu ui 库,想试着用一下。这个 UI 库的 button 元素可以通过设置 type 来调节不同的样式。
<button type="primary" class="ui-button">主按钮</button>
但是这样使用的话 ts 会报错,因为原生的 button type 属性是 'submit' | 'reset' | 'button' | undefined ,其中并没有 primary 这个类型。
我试着这样扩展 ButtonHTMLAttributes 这个接口:
declare module 'react' {
interface ButtonHTMLAttributes<T> extends HTMLAttributes<T> {
type?: 'submit' | 'reset' | 'button' | 'primary' | undefined;
}
}
ts 还是会提示必须是相同的类型,找了一圈没找到解决办法,大家有什么解决办法吗?