Skip to content

Commit bee26c8

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 bee26c8

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

lib/anime.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6407,7 +6407,7 @@ const createDraggable = (target, parameters) => new Draggable(target, parameters
64076407

64086408
/**
64096409
* @typedef {Object} ReactRef
6410-
* @property {HTMLElement|SVGElement} [current]
6410+
* @property {HTMLElement|SVGElement|null} [current]
64116411
*/
64126412

64136413
/**

src/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
/**
2222
* @typedef {Object} ReactRef
23-
* @property {HTMLElement|SVGElement} [current]
23+
* @property {HTMLElement|SVGElement|null} [current]
2424
*/
2525

2626
/**

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;

types/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5712,7 +5712,7 @@ const createDraggable = (target, parameters) => new Draggable(target, parameters
57125712

57135713
/**
57145714
* @typedef {Object} ReactRef
5715-
* @property {HTMLElement|SVGElement} [current]
5715+
* @property {HTMLElement|SVGElement|null} [current]
57165716
*/
57175717
/**
57185718
* @typedef {Object} AngularRef

0 commit comments

Comments
 (0)