Angular 升级后生成错误 - 无法分配 MediaQueryList 类型的 MediaQueryListEvent

Build error after Angular upgrade - MediaQueryListEvent not assignable of type MediaQueryList

我已将 Angular 版本从 5.2 升级到 7.2.0 并使用以下版本的软件包:

"@angular/flex-layout": "^7.0.0-beta.22", 打字稿版本3.2.2,“@angular/cdk”:7.2.1, "@angular/cli : 7.1.4"

我遇到构建错误:

'MediaQueryListEvent' is not assignable of type MediaQueryList.

代码:

export class LayoutComponent implements OnInit, OnDestroy {

  private _router: Subscription;

  mediaMatcher: MediaQueryList = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`);
  url: string;
  sidePanelOpened;

  constructor (
    private _element: ElementRef,
    private router: Router) {
    this.mediaMatcher.addListener(mql => zone.run(() => {
      this.mediaMatcher = mql; //i am getting error here Type 'MediaQueryListEvent' is not assignable to type 'MediaQueryList'.
                  //Property 'onchange' is missing in type 'MediaQueryListEvent'.
    }));
  }
 }

我该如何解决这个问题?

您好,您可以尝试更改此行

zone.run(() => this.mediaMatcher = mql));

为此

zone.run(() => this.mediaMatcher = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`)));