属性 'type' 在按钮上不存在
Property 'type' does not exist on button
我有这个按钮组件:
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
small?: boolean;
}
class Button extends React.Component<ButtonProps> { ... }
但是当我尝试这样做时:
<Button type="submit"></Button>
我收到这个错误:
Property 'type' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'
为什么? type
属性不是 React.HTMLAttributes<HTMLButtonElement>
的一部分吗? proper/recommended 设置此属性的方法是什么?
export interface ButtonProps
extends React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> {
small?: boolean
}
class ButtonZ extends React.Component<ButtonProps> {
render() {
return <></>
}
}
如果您使用 VSCode 作为 IDE 将鼠标悬停在 HTML 组件上并检查工具提示是查看类型和属性的好方法。
我有这个按钮组件:
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
small?: boolean;
}
class Button extends React.Component<ButtonProps> { ... }
但是当我尝试这样做时:
<Button type="submit"></Button>
我收到这个错误:
Property 'type' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'
为什么? type
属性不是 React.HTMLAttributes<HTMLButtonElement>
的一部分吗? proper/recommended 设置此属性的方法是什么?
export interface ButtonProps
extends React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> {
small?: boolean
}
class ButtonZ extends React.Component<ButtonProps> {
render() {
return <></>
}
}
如果您使用 VSCode 作为 IDE 将鼠标悬停在 HTML 组件上并检查工具提示是查看类型和属性的好方法。