Skip to content

Conversation

MoOx
Copy link
Contributor

@MoOx MoOx commented Oct 2, 2025

This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect).

This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect)
@MoOx MoOx requested a review from necolas as a code owner October 2, 2025 17:32
@meta-cla meta-cla bot added the cla signed label Oct 2, 2025
@MoOx
Copy link
Contributor Author

MoOx commented Oct 2, 2025

Well actually this is not enough. The type is not accessible anyway.
I will let this open to continue discussion about exported types.
Currently there is plenty of types I would be glad to import like this one, but they should be somehow reexported at the root of the package.
Is this something you will be ok with ?

Because otherwise, like said in the PR initial description, all the non-exported type at the package level need to be re-written.

@MoOx MoOx marked this pull request as draft October 2, 2025 17:36
@necolas
Copy link
Contributor

necolas commented Oct 2, 2025

We use Flow to get the prop types from the component

React.PropsOf<html.div>
React.PropsOf<html.div>['onClick']

@javascripter
Copy link
Contributor

javascripter commented Oct 3, 2025

For TypeScript you can do something like the below:

type StrictClickEventHandler = NonNullable<React.ComponentProps<typeof html.div>['onClick']>

// if you want to get the click event type itself
type StrictClickEvent =  Parameters<StrictClickEventHandler>[0]
// or 
type StrictClickEvent =  StrictClickEventHandler extends (event: infer E) => any ? E : never

React.ComponentProps works well as long as the prop types do not rely on generics (e.g. type Props<T> = { onFoo: (arg: T) => void }), meaning it works fine for RSD.

@necolas
Copy link
Contributor

necolas commented Oct 4, 2025

I think this type is a leftover from the early days when we had types like StrictHTMLElement. So it might be best to first FlowFixMe this event. Later we can properly type the event props to match what's expected on web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants