gluestack-ui icon indicating copy to clipboard operation
gluestack-ui copied to clipboard

Menu onSelectionChange type definition causing errors

Open trumpet2012 opened this issue 1 year ago • 1 comments

Description

Menu onSelectionChange not resolving to correct type.

CodeSandbox/Snack link

https://snack.expo.dev/@trumpet2012/gluestack-menu-typescript-issue

Steps to reproduce

See provided snack link for reproducible issue (note that the types aren't working in the snack for some reason but that code is enough to see the issue locally)

This is a copy of the example from the docs: https://v1.gluestack.io/ui/docs/components/overlay/menu#selection.

The typescript error is:

Property 'currentKey' does not exist on type 'Selection'.
     Property 'currentKey' does not exist on type '"all"'.

Adding an extra check to ensure that "keys" isn't "all" then leads to the following typescript error:

Property 'currentKey' does not exist on type 'Set<Key>'.

gluestack-ui Version

1.1.42

Platform

  • [X] Expo
  • [X] React Native CLI
  • [ ] Next
  • [ ] Web
  • [X] Android
  • [ ] iOS

Other Platform

No response

Additional Information

The type for the "keys" argument appears to be resolving to: https://github.com/adobe/react-spectrum/blob/8ee84717884461e0646236b77c9e43c5d14e3533/packages/%40react-types/shared/src/selection.d.ts#L28

However the actual keys object type looks like it should be using: https://github.com/adobe/react-spectrum/blob/8ee84717884461e0646236b77c9e43c5d14e3533/packages/%40react-stately/selection/src/Selection.ts#L19.

trumpet2012 avatar Jul 18 '24 19:07 trumpet2012

Looking into this more it looks like gluestack is using the older "react-stately" package: https://github.com/adobe/react-spectrum/blob/react-stately%403.21.0/packages/react-stately/src/index.ts for defining the type instead of the newer "@react-stately" package.

Edit: not sure if this is a case of older vs newer package. I'm unfamiliar with that code base. I am however starting to think that this might be an issue with the types provided by react-spectrum.

trumpet2012 avatar Jul 18 '24 20:07 trumpet2012