fix: createScope root param type for ReactRef #971
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, this is such an amazing library, thank you to everyone who has contributed to making it so lovely.
Issue
The
createScope
method acceptsScopeParams
which allows theroot
property to beReactRef
as part of the union and that type does not acceptnull
.The React libraries type definition for refs is currently:
type Ref<T> = RefCallback<T> | RefObject<T | null> | null;
null
is the valid state for React refs attached to DOM nodes during their initial render or when unmounting, so ifcreateScope
should allow passing the ref directly, as currently shown in the documentation,null
should be allowed.For example (from the current docs):
This would currently have a typescript error for
root
:Type 'null' is not assignable to type 'HTMLElement | SVGElement | undefined'
I did not encounter any type errors that did not already exist (on "master" there is currently an
AbortSignal
error), and since theScope
class does a truthy check (if (rootParam) { //... }
) I believe this change shouldn't cause any issues sinceundefined
is already accounted for and not explicitly checked.