resize-observer-polyfill icon indicating copy to clipboard operation
resize-observer-polyfill copied to clipboard

DOMRectReadOnly is not compatible with native TypeScript type

Open jcubic opened this issue 3 years ago • 0 comments

Type used by the polyfill is not compatible with DOMRectReadOnly that is in TypeScript so you can use this this type. (the error when using this type is that toJSON is missing). So the types should use native implementation or export that interface.

I've needed to add type when creating abstract class:

export abstract class AbstractResizedBase implements OnInit, OnDestroy {

  private observer: ResizeObserver;

  constructor(protected readonly element: ElementRef) { }

  // I need to add type here for param so I've needed to copy paste the interface into my file
  protected abstract onResize(rect: DOMRectReadOnly): void; 

  public ngOnInit(): void {
    this.observer = new ResizeObserver((entries: ResizeObserverEntry[]) => {
      const [ entry ] = entries;
      this.onResize(entry.contentRect);
    });
    this.observer.observe(this.element.nativeElement);
  }

  public ngOnDestroy(): void {
    this.observer.disconnect();
  }
}

jcubic avatar Sep 03 '20 15:09 jcubic