Skip to content

buttonTypes

Reports button elements without an explicit type attribute.

✅ This rule is included in the jsx logical and logicalStrict presets.

Button elements without an explicit type attribute default to type="submit", which can cause unintended form submissions. This rule requires that all <button> elements have an explicit type attribute set to one of the valid values: "button", "submit", or "reset".

Specifying an explicit type makes the button’s behavior clear and prevents accidental form submissions.

<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>Click me</
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>
<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
DOMAttributes<HTMLButtonElement>.onClick?: MouseEventHandler<HTMLButtonElement> | undefined
onClick
={
const handleClick: any
handleClick
}>Submit</
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>;
<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
type="invalid">Click</
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>
Error ts(2322) ― Type '"invalid"' is not assignable to type '"submit" | "reset" | "button" | undefined'.

If your codebase exclusively uses buttons in forms where the default submit behavior is never a concern, you might choose to disable this rule. However, it’s generally recommended to be explicit about button types for clarity and maintainability.

Made with ❤️‍🔥 around the world by the Flint team and contributors.