Skip to content

Typings collide with Typescripts DOM typings for ResizeObserver #83

Description

@csvn

Summary

The types added to global by importing 'resize-observer-polyfill' clash with Typescript's own typings for ResizeObserver in lib.dom.d.ts. This issue makes it very inconvenient to use this package.

import ResizeObserver from 'resize-observer-polyfill';

const resizeObserver = new ResizeObserver(entries => {
                                       // ^^^^^^^ Error: Parameter 'entries' implicitly has an 'any' type.
  console.log(entries);
});
// tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "lib": [
      "ES2015",
      "DOM"
    ]
  }
}
  • typescript@4.2.3
  • resize-observer-polyfill@1.5.1

image

Suggestions

  1. 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 reason lib.dom.d.ts is not used.

    import ResizeObserver, { ResizeObserverEntry } from 'resize-observer-polyfill';
    // or
    import ResizeObserver from 'resize-observer-polyfill';
    import type { ResizeObserverEntry } from 'resize-observer-polyfill';
  2. Avoid using custom types, and rely on typescripts own types.

    // src/index.d.ts
    export default ResizeObserver;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions