Skip to content

Commit 7da1f9d

Browse files
fix: createScope root param type for ReactRef
The `createScope` method accepts `ScopeParams` which allows the `root` property to be `ReactRef` as part of the union and that type does not accept `null`. 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 if `createScope` should allow passing the ref directly, as currently shown in the documentation. For example (from the current docs): ```jsx // ... const scope = useRef(null); useEffect(() => { scope.current = createScope({ root }) // ... return ( <div ref={root}> //... ``` This would currently have a typescript error for `root`: `Type 'null' is not assignable to type 'HTMLElement | SVGElement | undefined'`
1 parent 3552e70 commit 7da1f9d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ declare class Scope {
771771
}
772772
declare function createScope(params?: ScopeParams): Scope;
773773
type ReactRef = {
774-
current?: HTMLElement | SVGElement;
774+
current?: HTMLElement | SVGElement | null;
775775
};
776776
type AngularRef = {
777777
nativeElement?: HTMLElement | SVGElement;

0 commit comments

Comments
 (0)