-
Notifications
You must be signed in to change notification settings - Fork 928
Add types for Service Worker Controller #673
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
Conversation
Updates TypeScript to 2.8.1, which has much better WebWorker and Notification typings
|
||
// Not the whole interface, just the parts we're currently using. | ||
// If TS claims that something does not exist on this, feel free to add it. | ||
interface ServiceWorkerGlobalScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not already exist as a TSLib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It exists (as a type definition file), but it can't be used simultaneously with DOM.
microsoft/TypeScript#20595
microsoft/TypeScript#14687
So I took some parts of it that we need (and doesn't conflict with DOM) and put them here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Let's just add a link to the actual file and keep an eye on if we can undo this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, just noticed the typescript update. Lets go ahead and pull that from this PR and do it in a separate one for the whole repo?
const FCM_MSG = 'FCM_MSG'; | ||
|
||
export type BgMessageHandler = (input: any) => Promise<any>; | ||
export type BgMessageHandler = (input: Payload) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could be expecting a promise to be returned here so you can pass the promise to event.waitUntil(). Otherwise the service worker could be terminated before the developers work has finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, thanks!
Created #676 for dependency upgrades. |
This reverts commit 306f97c. Forgot to run `yarn` after switching branches, which made the push hook run the updated version of prettier, which created this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, after we get tests passing this LGTM 👍
They should pass once #676 is merged. |
Also updates TypeScript to 2.8.1, which has much better WebWorker and Notification typings, which allowed me to remove some more "any" casts.