Replies: 3 comments 6 replies
-
I started a PR for the integration hooks |
Beta Was this translation helpful? Give feedback.
-
The returned props are intentionally very broad. You should treat them as opaque implementation details and spread them directly onto DOM elements or pass them around as a whole rather than individually. This allows us to change the implementation in the future to return more or less props without breaking changes. If we typed each prop individually, then we could never remove props, and adding props would also potentially break things if only the previously used props were passed around. I'm curious where you're seeing TS errors. It makes me think the returned props are being used somewhere other than being spread on a DOM element, which seems like it would be problematic. |
Beta Was this translation helpful? Give feedback.
-
@devongovett I traced it back to the following: interface FocusEvent<T = Element> extends SyntheticEvent<T, NativeFocusEvent> {
relatedTarget: EventTarget | null;
target: EventTarget & T;
} From react-spectrum interface FocusEvent<Target = Element, RelatedTarget = Element> extends SyntheticEvent<Target, NativeFocusEvent> {
relatedTarget: (EventTarget & RelatedTarget) | null;
target: EventTarget & Target;
} So I wonder, if I run a different version of @types/react than react-spectrum, would typings be slightly different? |
Beta Was this translation helpful? Give feedback.
-
Im using
useKeyboard
which returns{ keyboardProps }
.These
keyboardProps
are typed too generically withHTMLAttributes<HTMLElement>
, because they only setonKeyDown
andonKeyUp
and all the other possibly collide if a component allows other types.react-spectrum/packages/@react-aria/interactions/src/useKeyboard.ts
Lines 22 to 37 in f6c0660
I think it's great to type the input of the hooks generically, but the output should be typed specifically to avoid type collisions with custom made components.
Typescript's utility type
Pick<T, Keys>
could be utilized to improve these typings, like:Otherwise I get this TS error for my custom
onChange
event:Any hook result with a generic type would need a refactoring:
https://github.com/adobe/react-spectrum/search?q=HTMLAttributes%3CHTMLElement%3E
Beta Was this translation helpful? Give feedback.
All reactions