Skip to content
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

DOMRectReadOnly is not compatible with native TypeScript type #73

Open
jcubic opened this issue Sep 3, 2020 · 0 comments
Open

DOMRectReadOnly is not compatible with native TypeScript type #73

jcubic opened this issue Sep 3, 2020 · 0 comments

Comments

@jcubic
Copy link

jcubic commented Sep 3, 2020

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();
  }
}
jonastieppo added a commit to jonastieppo/resize-observer-polyfill that referenced this issue Jan 27, 2023
This unique line solves the following error when updating for newer TS versions:

Error: node_modules/resize-observer-polyfill/src/index.d.ts:19:18 - error TS2717: Subsequent property declarations must have the same type.  Property 'contentRect' must be of type 'DOMRectReadOnly', but here has type 'DOMRectReadOnly'.

It is related with issues que-etc#80, que-etc#53 and que-etc#73.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant