[英]Property 'type' does not exist on button
I have this button component:我有这个按钮组件:
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
small?: boolean;
}
class Button extends React.Component<ButtonProps> { ... }
But when I try to do:但是当我尝试这样做时:
<Button type="submit"></Button>
I get this error:我收到此错误:
Property 'type' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode;
类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; 上不存在属性“类型” }>'
}>'
Why?为什么? Isn't the
type
attribute part of React.HTMLAttributes<HTMLButtonElement>
? type
属性不是React.HTMLAttributes<HTMLButtonElement>
的一部分吗? What is the proper/recommended way to set this attribute?设置此属性的正确/推荐方法是什么?
export interface ButtonProps
extends React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> {
small?: boolean
}
class ButtonZ extends React.Component<ButtonProps> {
render() {
return <></>
}
}
If you're using VSCode as your IDE hovering over an HTML component and inspecting the tooltip is a good way to see the types and props.如果您使用 VSCode 作为 IDE 悬停在 HTML 组件上并检查工具提示是查看类型和道具的好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.