Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TypeScript] - Can't set button type attribute

See original GitHub issue
Screen Shot 2020-01-16 at 5 33 52 PM
TS2322: Type '{ children: Element; type: string; disabled: boolean; color: "primary" | "light"; loading: boolean; onClick: () => Promise<void>; }' is not assignable to type 'IntrinsicAttributes & ButtonProps & RefAttributes<any>'.   Property 'type' does not exist on type 'IntrinsicAttributes & ButtonProps & RefAttributes<any>'.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

leandroaphermescommented, Aug 25, 2022

I’m using it like this

export type ButtonProps = {
  icon?: React.ReactElement;
  loading?: boolean;
  htmlType?: React.ButtonHTMLAttributes<HTMLButtonElement>["type"];
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "type" | "color">;
clehenecommented, Jan 17, 2020

Not a bug. This should be passed as submit attribute. I seem to hit this repeatedly. Couldn’t Button instead inherit ButtonHTMLAttributes

 interface ButtonHTMLAttributes<T> extends HTMLAttributes<T> {
        autoFocus?: boolean;
        disabled?: boolean;
        form?: string;
        formAction?: string;
        formEncType?: string;
        formMethod?: string;
        formNoValidate?: boolean;
        formTarget?: string;
        name?: string;
        type?: 'submit' | 'reset' | 'button';
        value?: string | string[] | number;
Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the point of <button type="button">? - Stack Overflow
So setting the type to "button" disables the default behaviour of submitting a form so you won't need to use preventDefault to handle...
Read more >
Useful Patterns by Use Case - React TypeScript Cheatsheets
A very common use case for this is to render something as either a button or an anchor, based on if it receives...
Read more >
Your Button component should default to `type="button"`
I'm restricting the value to "submit" | undefined , so that only type="submit" is allowed. (Omitting the prop is also allowed.)
Read more >
Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >
How to disable a Button in TypeScript | bobbyhadz
Select the button element. · Use the setAttribute() method to set the disabled attribute. · For example, btn?.setAttribute('disabled', '') .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found