Type 'RefObject<HTMLElement> | undefined' is not assignable to type 'string | ((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement> | null | undefined'.
Type 'RefObject<HTMLElement>' is not assignable to type 'string | ((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement> | null | undefined'.
Type 'RefObject<HTMLElement>' is not assignable to type 'RefObject
To workaround it, I had to cast the ref every time. This is a bit verbose though
I made the ResizeDetector typings take an optional generic type that defaults to HTMLElement (same as today). This way, instead of having to do an explicit cast, we can just instantiate the <ResizeDetector> with that generic type.
Motivation
While using this library in Typescript, I noticed that I had to cast
targetRef
to avoid typing errors.This code:
Would result in this error:
To workaround it, I had to cast the ref every time. This is a bit verbose though
Fix
I made the ResizeDetector typings take an optional generic type that defaults to HTMLElement (same as today). This way, instead of having to do an explicit cast, we can just instantiate the
<ResizeDetector>
with that generic type.Now, I can just write:
Testing
Installed package on my own project and ensured that it was working.