question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error TS2430: Interface 'Window' incorrectly extends interface 'WindowEventHandlers'

See original GitHub issue

I’m using it in angular 8 app and recently it started to throw this error:

ERROR in node_modules/typescript/lib/lib.dom.d.ts:17123:11 - error TS2430: Interface ‘Window’ incorrectly extends interface ‘WindowEventHandlers’. Types of property ‘onunhandledrejection’ are incompatible. Type ‘((this: Window, ev: PromiseRejectionEvent) => any) | null’ is not assignable to type ‘((this: WindowEventHandlers, ev: PromiseRejectionEvent) => any) | null’. Type ‘(this: Window, ev: PromiseRejectionEvent) => any’ is not assignable to type ‘(this: WindowEventHandlers, ev: PromiseRejectionEvent) => any’. The ‘this’ types of each signature are incompatible. Type ‘WindowEventHandlers’ is missing the following properties from type ‘Window’: Blob, TextDecoder, TextEncoder, URL, and 225 more.

17123 interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, GlobalFetch, WindowOrWorkerGlobalScope, WindowEventHandlers {

Now, I get this error only when I use strict=true in tsconfig.json. But it wokder with previous versions of this package without any issue.

I did check - if I remove microsoft/applicationinsights-web package and related code everything works. So this is clearly the proble with microsoft/applicationinsights-web.

Here’s the angular service which causes the problem:


import { Injectable, OnInit } from "@angular/core";
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
import { ActivatedRouteSnapshot, ResolveEnd, Router } from "@angular/router";
import { filter, map } from "rxjs/operators";
import { Subscription } from "rxjs";
import { environment } from "src/environments/environment";

@Injectable({
  providedIn: "root"
})
export class AppInsightsService {
  private routerSubscription: Subscription;

  private appInsights = new ApplicationInsights({
    config: {
      instrumentationKey: environment.production
        ? "b6f62105-85a5-4055-b483-466d57ebb263" // production
        : "b9eb5e3c-0581-4bb4-ad69-234d3ab7c8fd" // dev
    }
  });

  constructor(private router: Router) {
    this.appInsights.loadAppInsights();
    this.routerSubscription = this.router.events
      .pipe(
        filter(event => event instanceof ResolveEnd),
        map(ev => ev as ResolveEnd)
      )
      .subscribe((event: ResolveEnd) => {
        const activatedComponent = this.getActivatedComponent(event.state.root);
        if (activatedComponent) {
          this.logPageView(
            `${activatedComponent.name} ${this.getRouteTemplate(
              event.state.root
            )}`,
            event.urlAfterRedirects
          );
        }
      });
  }

  setUserId(userEmail: string) {
    this.appInsights.setAuthenticatedUserContext(userEmail);
  }

  clearUserId() {
    this.appInsights.clearAuthenticatedUserContext();
  }

  logPageView(name?: string, uri?: string) {
    this.appInsights.trackPageView({ name, uri });
  }

  private getActivatedComponent(snapshot: ActivatedRouteSnapshot): any {
    if (snapshot.firstChild) {
      return this.getActivatedComponent(snapshot.firstChild);
    }

    return snapshot.component;
  }

  private getRouteTemplate(snapshot: ActivatedRouteSnapshot): string {
    let path = "";
    if (snapshot.routeConfig) {
      path += snapshot.routeConfig.path;
    }

    if (snapshot.firstChild) {
      return path + this.getRouteTemplate(snapshot.firstChild);
    }

    return path;
  }
}

Removing it removes the error.

Windows 10 x64, node 12.14.1, typescript 3.5.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
MSNevcommented, Feb 6, 2020

The Hotfix v2.4.4 release (which includes this change) is now fully deployed.

0reactions
github-actions[bot]commented, Aug 15, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error 2430: Interface 'InAppBrowser' incorrectly extends ...
Interface 'InAppBrowser' incorrectly extends interface 'Window'. Types of property 'addEventListener' are incompatible. Type '{ (type: " ...
Read more >
@microsoft/applicationinsights-shims | Yarn - Package Manager
... CDN) they are built using the polyfill pattern, so if a global implementation of __extends() and __assign() already exist those versions will...
Read more >
node_modules/typescript/lib/lib.dom.d.ts - Google Git
interface ElementDefinitionOptions {. extends?: string;. } interface ErrorEventInit extends EventInit {. colno?: number;. error?: any;. filename?: string;.
Read more >
@microsoft/applicationinsights-web: Versions | Openbase
#1875 [BUG] error thrown using basic version + NPM setup ... #1182 Fix error TS2430: Interface 'Window' incorrectly extends interface 'WindowEventHandlers' ...
Read more >
How to Easily Extend Interfaces in TypeScript - Webtips
interface Person { age: number } // ❌ This will cause the below error: // Interface 'Employee' incorrectly extends interface 'Person'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found