-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typings collide with Typescripts DOM typings for ResizeObserver #83
Comments
Can I ask what version of typescript you are using. I asked because I update to 4.2.3 from 4.0.2 and I got the same error you got. Plus the validation is not passing for resize-observer-polyfill.
It seems that the resize-observer-polyfill is obsolete and typescript made the implementation. edit: Note that the latest version of VSCode ship with 4.2.3. So your validation might pass but you would get the error when opening the file. |
@bmeunier1974 yeah, I missed specifying what TS version I was using. The above is with the latest version; |
You don't need to use the polyfill with Typescript 4.2.3. Removing resize-observer-polyfill should fix those errors. |
Typescript does not polyfill. We need the polyfill so that older browsers get the code. |
Sorry, I assumed you were using it to get type definition like I did. |
No problem! We're currently dynamically loading polyfills if we detect they are required, so we do something similar to this (but with several different checks and polyfills bundled together): if (!('ResizeObserver' in window)) {
await import('resize-observer-polyfill').then(m => window.ResizeObserver = m.default);
} The issue is that as soon as this package is imported, it adds global interfaces, creating errors like in the issue description in other places. A workaround for now is to add explicit typing for the callback parameter, which seems to avoid the issue: new ResizeObserver((entry: ResizeObserverEntry[]) => { ... }); |
We target only the latest version of chrome so we don't have problem. I assume it was use for type definition. But I don't see anything why it would be needed. But apparently there was a breaking change in TS 4.2 on how lib.d.ts are handled. As with every TypeScript version, declarations for lib.d.ts (especially the declarations generated for web contexts), have changed. There are various changes, though Intl and ResizeObserver’s may end up being the most disruptive. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html |
Is there any update / guidance on this?
We're unable to upgrade
|
We encounter this issue with |
For those using typescript 4.2.3 that just want to get on with it while we wait for our good maintainers to prepare a more comprehensive solution, add a file at your repository root diff --git a/node_modules/resize-observer-polyfill/src/index.d.ts b/node_modules/resize-observer-polyfill/src/index.d.ts
index 74aacc0..1b236d2 100644
--- a/node_modules/resize-observer-polyfill/src/index.d.ts
+++ b/node_modules/resize-observer-polyfill/src/index.d.ts
@@ -1,14 +1,3 @@
-interface DOMRectReadOnly {
- readonly x: number;
- readonly y: number;
- readonly width: number;
- readonly height: number;
- readonly top: number;
- readonly right: number;
- readonly bottom: number;
- readonly left: number;
-}
-
declare global {
interface ResizeObserverCallback {
(entries: ResizeObserverEntry[], observer: ResizeObserver): void then add to your npm scripts "postinstall": "npx patch-package" YMMV, I got some errors like
but that might be unrelated and part of ts 4.2.3 asserting it's "TypeScript is a superset of JavaScript" on my code style ;) I solved that one with a type assertion in the callback's params. |
use patch from que-etc/resize-observer-polyfill#83 (comment)
I believe PR #85 would fix the issue. |
I've published a fork at https://www.npmjs.com/package/truecar-resize-observer-polyfill. The only difference is the global type fix. This package hasn't had a release in 3 years, so you may want to look at other polyfills after this fix. |
Another possible workaround is to manually remap built-in definitions with own version in {
"compilerOptions": {
"paths": {
"resize-observer-polyfill": ["./my-types/resize-observer-polyfill"]
}
}
} and create file |
> Handle element resizes like it's 2021! In 2021, it's already been 1-3 years since major browsers started supporting ResizeObserver natively. Users who haven't updated their browser for that long are in trouble anyway. Application developers who still want to support such users, can just add back the dependency. The latest version of the polyfill has broken types (que-etc/resize-observer-polyfill#83), so it's a hassle to deal with. This requries a major version release.
> Handle element resizes like it's 2021! In 2021, it's already been 1-3 years since major browsers started supporting ResizeObserver natively. Users who haven't updated their browser for that long are in trouble anyway. Application developers who still want to support such users, can just add back the dependency. The latest version of the polyfill has broken types (que-etc/resize-observer-polyfill#83), so it's a hassle to deal with. This requries a major version release.
> Handle element resizes like it's 2021! In 2021, it's already been 1-3 years since major browsers started supporting ResizeObserver natively. Users who haven't updated their browser for that long are in trouble anyway. Application developers who still want to support such users, can just add back the dependency. The latest version of the polyfill has broken types (que-etc/resize-observer-polyfill#83), so it's a hassle to deal with. This requries a major version release.
I think this should be merged ASAP |
The last commit to this project was almost 3 years ago. I think it's unlikely that any PR will be merged. https://github.com/juggle/resize-observer could be an alternative. It seems to be more actively maintained (many more recent releases and commits). |
* Fix components that use deprecated EUI methods and properties * Remove `withTitle` * Remove `compressed` from `EuiFormRow` * Replace `compressed` with `formRowDisplay` on `ValidatedDualRange` * Apply newer EUI definitions to complaining components * Replace `resize-observer-polyfill` with `@juggle/resize-observer` and `@types/resize-observer-browser` due to [typing collision](que-etc/resize-observer-polyfill#83) Signed-off-by: Miki <[email protected]>
Summary
The types added to
global
by importing'resize-observer-polyfill'
clash with Typescript's own typings forResizeObserver
inlib.dom.d.ts
. This issue makes it very inconvenient to use this package.[email protected]
[email protected]
Suggestions
Since this package is trying to be used as a ponyfill, I don't think it should affect
global
with it's types as soon as it's imported. It's probably better that types are exported directly from the package if they are needed. Since there already are types provided by TS, this should likely not be needed unless for some reasonlib.dom.d.ts
is not used.Avoid using custom types, and rely on typescripts own types.
The text was updated successfully, but these errors were encountered: