TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

ResizeObserver not present on the Window interface

Open guillaumebrunerie opened this issue 2 years ago • 1 comments

The ResizeObserver class is only available as a global declaration and not on the Window interface. I think it should also be available on the Window interface for at least two reasons:

  • The specification (https://drafts.csswg.org/resize-observer/#idl-index) says [Exposed=(Window)], which I’m guessing means that it is supposed to be on the Window interface (I’m actually surprised, isn’t the specification supposed to be automatically translated to Typescript declarations?)
  • For applications with several windows, it behaves differently depending on the window from which it is taken (see https://codepen.io/Latcarf/pen/RwdyLXr?editors=0010). So it would make a lot of sense to be able to do the following, which currently doesn’t typecheck as popup is of type Window.
const popup = window.open(...)!;
new popup.ResizeObserver(...);

guillaumebrunerie avatar Feb 03 '24 11:02 guillaumebrunerie

says [Exposed=(Window)]

Window in this case is environment name, like DedicatedWorker or SecureContext (no such interfaces)

Also:

  1. Global ResizeObserver is fine
  2. There is no support for nested interfaces/types in TS
  3. It could't be implemented without duplication

turansky avatar Feb 12 '24 23:02 turansky