iconButton click property not compiling in Typescript
See original GitHub issueAFAIK, the iconButton should behaves as a button, so it should be able to received onClick property. I’ve tried something like this:
<IconButton onClick={() => {console.log("whatever")} {...more properties} >{children}</IconButton>
But I get a typescript compilation error because onClick property is not available.
I think the problem is with the types definition https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/theme-ui__components/index.d.ts#L335 because it uses BoxProps instead of IconButtonProps. Does it make sense?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to pass a handler to onClick with Typescript and material UI
I want to pass a function that returns another function to material UI's onTouchTap event: <IconButton ...
Read more >Making your components extensible with TypeScript
TypeScript is unable to infer onClick 's first argument correctly, which results in an any type. The reason is that our custom onClick...
Read more >Icon buttons - Material Design
The icon button will work without JavaScript, but you can enhance it to have a ripple effect by instantiating MDCRipple on the root...
Read more >property 'onclick' does not exist on type 'intrinsicattributes'
Typescript is complaining that onClick property does not exist when I try to use with the Sheet.Backdrop component. Here's the full error. Type...
Read more >React Tooltip component - Material UI - MUI
If you're not wrapping a MUI component that inherits from ButtonBase , for instance, a native <button> element, you should also add the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@martpie I’ve created a PR that will be merged soon (hopefully) https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44107
Typescript does not allow to add onClick property to the iconButton because it’s not in their available properties because according to https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/theme-ui__components/index.d.ts#L335 the iconButton has the properties of BoxProps instead of the IconButtonProps. I’ve just seen that I created the bug in the wrong repository. I’m quite new in Typescript and thought that types were maintained and pushed to DeclarationTypes from here but I think that repo has its own flow. Sorry for the noise here @lachlanjc , I’ll close the issue