react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

`@react-aria/button` wrong typescript bindings

Open mitas1 opened this issue 4 years ago • 4 comments

🐛 Bug Report

useButton(...) hook from @react-aria/button package is returning a wrong type.

🤔 Expected Behavior

I would expect the returned TypeScript types are correct and working.

😯 Current Behavior

Consider following simple example where typescript throws an error:

...
const { buttonProps } = useButton(props, ref);
        ^^^^^^^^^^^
        Unsafe array destructuring of a tuple element with an 'any' value.eslint@typescript-eslint/no-unsafe-assignment
...

💁 Possible Solution

For some reason in the installed generated TypeScript bindings located in node_modules/@react-aria/button/dist/types.d.ts, the ButtonHTMLAttributes type is not imported. After I've tried to properly import import { ButtonHTMLAttributes } from react in the types.d.ts it started to work. I've tried to build the whole react-spectrum locally and the bindings are generated correctly so maybe the publised dist folder contains outdated version?

🌍 Your Environment

Software Version(s)
react-spectrum 3.3.4
Browser X
Operating System MacOS

mitas1 avatar Jan 28 '22 13:01 mitas1

I think this might be a duplicate that'll be fixed when we next release react-aria https://github.com/adobe/react-spectrum/issues/1388 the fix is already merged, we just haven't re-released the package yet, but will in our next release you might be able to check with the nightly version

snowystinger avatar Jan 28 '22 18:01 snowystinger

@mitas1 Let us know if you are getting this still with 3.4.0 of @react-aria/button, I'm seeing the proper types being imported within the dist/types.d.ts now

LFDanLu avatar Feb 16 '22 00:02 LFDanLu

Hey @snowystinger and @LFDanLu i have recently started a project with version ^3.20.0 and can confirm this has been fixed if you want to close this issue.

xxKeefer avatar Nov 06 '22 07:11 xxKeefer

Thanks for checking on that!

snowystinger avatar Nov 06 '22 16:11 snowystinger