Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; }>'

Why? Isn't the type attribute part of React.HTMLAttributes<HTMLButtonElement>? What is the proper/recommended way to set this attribute?

like image 760
o01 Avatar asked Jan 24 '26 01:01

o01


1 Answers

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.

like image 86
Damian Green Avatar answered Jan 25 '26 17:01

Damian Green



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!