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

Service worker types for service worker event listener #40153

Open
juancarlosjr97 opened this issue Aug 20, 2020 · 3 comments
Open

Service worker types for service worker event listener #40153

juancarlosjr97 opened this issue Aug 20, 2020 · 3 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19
Milestone

Comments

@juancarlosjr97
Copy link

juancarlosjr97 commented Aug 20, 2020

TypeScript Version: 3.9.7

Search Terms:

serviceworker listener
serviceworker statechange
serviceworker onstatechange

Code

const updateServiceWorker = () => {
    const registrationWaiting = serviceWorkerRegistration?.waiting;

    if (registrationWaiting) {
      registrationWaiting.postMessage({ type: "SKIP_WAITING" });

      registrationWaiting.addEventListener("statechange", (e) => {
        if (e.target.state === "activated") {
          window.location.reload(true);
        }
      });
    }
  };

Expected behaviour:

Above event.target is ServiceWorker type

Actual behaviour:

Above event.target is EventTarget type

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Sep 3, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 3, 2020
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Sep 3, 2020
@sandersn sandersn added the PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19 label Sep 18, 2020
@sarahzhao25
Copy link

Hi ! @nlane and I want to work on this issue as part of vGHC OSD! Do we need to assign ourselves or anything for this?

@saschanaz
Copy link
Contributor

I guess this is essentially a duplicate of the old #299.

@gardner
Copy link

gardner commented Nov 23, 2021

waitingServiceWorker?.addEventListener('statechange', event => {
  const sw = event?.target as ServiceWorker;
  if (sw?.state === 'activated') {
    window.location.reload();
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19
Projects
None yet
Development

No branches or pull requests

6 participants