Typescript: ResizeObserver API declarations missing

Created on 13 Nov 2018  ·  21Comments  ·  Source: microsoft/TypeScript

Search Terms

ResizeObserver

Suggestion

lib.dom.ts does not include ResizeObserver API declarations.

Use Cases

ResizeObserver is a thing that is getting some support in 2018 and I've found no mention about ResizeObserver here.

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.
lib.d.ts Question

Most helpful comment

Time to add it, it has shipped to Safari last month. This means literally all browsers support it.

All 21 comments

I think it is intentional that the standard type definitions don't come with experimental APIs, especially if browser support is nearly not existing.

We generate the lib over at https://github.com/Microsoft/TSJS-lib-generator from the standarized web IDL files now. This file contains the list of IDLs we generate the lib from. Once the feature hits, eg, the whatwg common dom interfaces IDL, we'll sync and have it. It's going to be some time (and probably much better browser support) until that happens. I'd recommend just adding the extra declarations locally to your project in the meantime, as I don't think we'd take a PR for an override for something that's still experimental.

@weswigham good to know! Thank you.

I'd recommend just adding the extra declarations locally to your project in the meantime

What is the correct place to put these declarations from Typescript perspective? Taking into account the code of resize-observer-polyfill

Any file in your project will do. Many people would recommend a separate globals.d.ts or the like for things like this.

@weswigham This seemingly should be revisited these days?

All major browsers support it with the evergreen model in mind: Firefox (68-69), Safari (Tech Preview for availability in next Safari to launch alongside MacOS Catalina without a doubt), Chrome, Edge w/ Chromium, & so on.

There's also updated CaniUse data on the matter now, IIRC: https://caniuse.com/#search=ResizeObserver

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

This should re-open; I’m of the opinion the reason it’s closed is questionable.

The premise of not adding interface for ResizeObserver API is obsolete and needs an update.

/cc @weswigham

@weswigham Any update on this?

Still marked as experimental on mdn, so no. When the spec is moved out of draft state and accepted, it's associated IDL should get pulled in by TS and automatically included, but that hasn't happened yet.

@weswigham MDN no longer lists this API as experimental. Currently getting "Cannot find name 'ResizeObserver'" when trying to use the API with TypeScript 3.7.2

This issue should be reopened as it is no longer experimental and all major browsers support it.

According to MDN it's still only part of an Editor's Draft, and not all major browsers support it.

I imagine what’s holding things up is Safari that won’t support it until
2020 being on their 2020 roadmap; Edge support for it is guaranteed
~January 15th when Edge Chromium is set to launch for the public w/ it’s
support for ResizeObserver.

On Wed, Nov 13, 2019 at 1:00 AM Martin Johns notifications@github.com
wrote:

According to MDN it's still only part of an Editor's Draft, and not all
major browsers support it.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/TypeScript/issues/28502?email_source=notifications&email_token=AAJKUOAOKN35DZEYT26M6VLQTO6ZVA5CNFSM4GDOB24KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED5MEZQ#issuecomment-553304678,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJKUODKUSZ7BORN3AUGNKLQTO6ZVANCNFSM4GDOB24A
.

>

Kevin Lozandier
[email protected] lozandier@gmail.com

Any updates here?

that's one of the more bizarre issues I encountered. i've heard way much about this API the past year for it to be unfamiliar by typescript

Almost to 80% https://caniuse.com/#search=ResizeObserver

Time to add it, it has shipped to Safari last month. This means literally all browsers support it.

Up

While the typings aren't merged into typescript yet, you can use a package from npm with ResizeObserver typings: https://www.npmjs.com/package/@types/resize-observer-browser

To add to @denexapp's response:

1) install https://www.npmjs.com/package/@types/resize-observer-browser
2) /// <reference types="resize-observer-browser" /> at the top of the file where you need to use it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuit picture yuit  ·  3Comments

jumpinjackie picture jumpinjackie  ·  3Comments

romulus001 picture romulus001  ·  3Comments

RyanCavanaugh picture RyanCavanaugh  ·  3Comments

blmarket picture blmarket  ·  3Comments