Skip to content

ServiceWorkerRegistration.Update() should return Promise<ServiceWorkerRegistration> #31502

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

Open
ahardin13 opened this issue May 21, 2019 · 6 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@ahardin13
Copy link

TypeScript Version: 3.4.3

Search Terms:
ServiceWorkerRegistration Update

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
let isUpdating: boolean;
navigator.serviceWorker.getRegistration().then(sw => {
    sw.update().then(result => {
        if (result.installing || result.waiting) {
            isUpdating = true;
        }
    });
});

Expected behavior:
result is of type ServiceWorkerRegistration and result.installing and result.waiting are valid.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/update

Actual behavior:
result is of type void and tsc gives errors
error TS2339: Property 'installing' does not exist on type 'void'.
error TS2339: Property 'waiting' does not exist on type 'void'.

Playground Link

Related Issues:
#17590

@ahardin13
Copy link
Author

It looks to me like this definition is what needs to be updated.

update(): Promise<void>;

@ahardin13
Copy link
Author

After digging through how the changes would be made, I found the typescript definition matches the w3c spec. https://w3c.github.io/ServiceWorker/#serviceworkerregistration

Any guidance on if I should follow-up on that spec or stick with the current definition and not use Chrome's implementation?

@MartinJohns
Copy link
Contributor

On MDN they write for Chrome:

Starting with Chrome 46, update() returns a promise that resolves with 'undefined' if the operation completed successfully or there was no update, and rejects if update failed. If the new worker ran but installation failed, the promise still resolves. Formerly, it raised an exception.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jun 13, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 13, 2019
@olback
Copy link

olback commented Sep 28, 2019

On MDN they write for Chrome:

Starting with Chrome 46, update() returns a promise that resolves with 'undefined' if the operation completed successfully or there was no update, and rejects if update failed. If the new worker ran but installation failed, the promise still resolves. Formerly, it raised an exception.

This seems to have changed. Running the update method in Chromium 77, I get a ServiceWorkerRegistration object back.

Edit: Tried it in Firefox 69 as well, same result as in Chromium 77.

@dlech
Copy link

dlech commented Jan 28, 2021

It looks like this need to be fixed here: https://github.com/microsoft/TypeScript-DOM-lib-generator

@Bashamega
Copy link

Duplicate of microsoft/TypeScript-DOM-lib-generator#1684

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants