que-etc / resize-observer-polyfill

A polyfill for the Resize Observer API
MIT License
1.75k stars 132 forks source link

DOMRectReadOnly interface type miss toJSON() method #53

Open IlCallo opened 5 years ago

IlCallo commented 5 years ago

Trying to contentRect property with right type, but native DOMRectReadOnly has a toJSON method that your interface doesn't have, this results into a type mismatch.

xinghul commented 5 years ago

would be great to also export your version of DOMRectReadOnly.

concatime commented 4 years ago

I second this. https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L4133

JSXS commented 4 years ago

I've got a function that I was trying to pass entry.contentRect to, so for the meantime, I'm just defining the argument as Partial<DOMRectReadOnly> for now.

...

const myFunction = (domRect: Partial<DOMRectReadOnly>) => {/*do something*/}

...

for ( const entry of entries) {
   myFunction(entry.contentRect); //works
}

Argument of type "DOMRectReadOnly" is not assignable to parameter of the type "DOMRectReadOnly"

But yeah, either just having this package use TypeScript's built-in DOMRectReadOnly or exporting the one defined by this package would be nice.