Typescript: DOM lib is missing Intersection Observer API on window global

Created on 4 Jun 2017  路  4Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.3.4

Code

The browser Intersection Observer API defines these on the window:

window.IntersectionObserver
window.IntersectionObserverEntry

Expected behavior:
These should be defined in the DOM lib typings.

Actual behavior:
They are not defined, so I get type errors.

Bug lib.d.ts help wanted

Most helpful comment

As a temporary fix

export {}
declare global {
  interface Window {
    IntersectionObserver: typeof IntersectionObserver
  }
}

All 4 comments

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

Can this issue be closed? Looks like the change has already been merged into master?

Aha, looks like they are in the typings, just not exposed on the window interface:

new IntersectionObserver(() => {}); // no error
window.IntersectionObserver // error: Property 'IntersectionObserver' does not exist on type 'Window'.

As a temporary fix

export {}
declare global {
  interface Window {
    IntersectionObserver: typeof IntersectionObserver
  }
}

Was this page helpful?
0 / 5 - 0 ratings