-
Notifications
You must be signed in to change notification settings - Fork 38
More generalized props type for ref and type variables #637
Conversation
Would you rebase past this? #638 |
@mattdamon108 |
Sorry I did not see it's there. Ignore me. |
b3215f6
to
d5edfe7
Compare
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
Do all the examples compile fine?
Perhaps 1 more line of comment on where the removed Js.Nullable.t is coming from (2nd arg of forwardRef).
Should Js.nullable
be removed in addition of Js.Nullable.t
, in case some details of the bindings change in future?
It is fine in the example project. I’m going to run more in my company project. Let you know the result.
Can I ask what you mean |
Great. I'll merge assuming there are no issues. If there are, we can revisit.
Sorry I meant function |
Ah! It’s little tricky part, though. If the 2nd arg of forwardRef can be sure not a null value, we can use the option type, instead of Js.Nullable.t. Not a very clear picture how to improve this part now, but we can tackle this part later to improve more cleaner and less magic. |
This PR has two purposes.
1. The props type with unbounded type variables
Fix the issue https://forum.rescript-lang.org/t/call-for-help-test-the-react-jsx-v4/3713/57?u=moondaddi, which is how to handle type variables for making props type.
2. More generalized type for ref
The above issue reminds me that the constraint of type ref. The type constraint
ReactDOM.Ref.currentDomRef
is not flexible in case the JSX ppx is used with other jsx libraries, such as React Native. The type of ref would be different in each library.Without type annotation for ref,
ReactDOM.Ref.currentDomRef
as defaultWith type annotation
Js.Nullable.t<'ref>
is used for the runtime safety instead ofoption<'ref>
, because the value of ref could benull
.'ref
should be used in the props type for calling from the other application sites.