Skip to content

DOMRectReadOnly is not compatible with native TypeScript type #73

Description

@jcubic

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();
  }
}

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