question-mark
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.

iconButton click property not compiling in Typescript

See original GitHub issue

AFAIK, 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jjballano-qatiumcommented, Apr 23, 2020

@martpie I’ve created a PR that will be merged soon (hopefully) https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44107

1reaction
jjballano-qatiumcommented, Apr 22, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found