TypeScript: ResizeObserver API declarations missing
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:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 56
- Comments: 27 (6 by maintainers)
Commits related to this issue
- fix(resize): uses `ResizeObserver` if possible As discussed in #4233, ResizeObserver is now widely available (>90% as of 15/01/2021) so we can use it instead of a custom-built solution to listen to r... — committed to iamricard/svelte by iamricard 3 years ago
- fix(resize): uses `ResizeObserver` if possible As discussed in #4233, ResizeObserver is now widely available (~90% as of 15/01/2021, [source](http://caniuse.com/?search=ResizeObserver)) so we can use... — committed to iamricard/svelte by iamricard 3 years ago
- Navigation component + Page/Layout concept (#42) This PR adds the navigation component, and also reworks the react-router usage into a Page and Layout system. For the Navigation resizing, I tried ... — committed to yext/search-headless-react by oshi97 3 years ago
Time to add it, it has shipped to Safari last month. This means literally all browsers support it.
Up
This should re-open; I’m of the opinion the reason it’s closed is questionable.
The premise of not adding interface for
ResizeObserverAPI is obsolete and needs an update./cc @weswigham
@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
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.
I think it is intentional that the standard type definitions don’t come with experimental APIs, especially if browser support is nearly not existing.
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
Any updates here?
@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
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
According to MDN it’s still only part of an Editor’s Draft, and not all major browsers support it.
To add to @denexapp’s response:
/// <reference types="resize-observer-browser" />at the top of the file where you need to use it.This issue should be reopened as it is no longer experimental and all major browsers support it.
Almost to 80% https://caniuse.com/#search=ResizeObserver
@MartinJohns Yeah, after upgrading to
4.2.3, it works perfectly, thanks!To me, the solution is:
@types/resize-observer-browsertotypesfield intsconfig.jsonfile.Just like:
Why does not just ResizeObserver | undefined type?