ZeeCoder / use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.
MIT License
644 stars 42 forks source link

ref cannot be used on div or canvas in TypeScript #12

Closed troyspencer closed 5 years ago

troyspencer commented 5 years ago

When trying to assign the ref to the ref prop on a div, as in the examples:

Type 'RefObject<HTMLElement>' is not assignable to type 'LegacyRef<HTMLDivElement>'.
  Type 'RefObject<HTMLElement>' is not assignable to type 'RefObject<HTMLDivElement>'.
    Property 'align' is missing in type 'HTMLElement' but required in type 'HTMLDivElement'.ts(2322)
lib.dom.d.ts(6346, 5): 'align' is declared here.
index.d.ts(96, 9): The expected type comes from property 'ref' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

When trying to assign the ref to the ref prop on a canvas:

Type 'RefObject<HTMLElement>' is not assignable to type 'LegacyRef<HTMLCanvasElement>'.
  Type 'RefObject<HTMLElement>' is not assignable to type 'RefObject<HTMLCanvasElement>'.
    Type 'HTMLElement' is missing the following properties from type 'HTMLCanvasElement': height, width, getContext, toBlob, and 2 more.ts(2322)
index.d.ts(96, 9): The expected type comes from property 'ref' which is declared here on type 'DetailedHTMLProps<CanvasHTMLAttributes<HTMLCanvasElement>, HTMLCanvasElement>'