Scenario
I am in the process of converting my service-worker file from JavaScript to TypeScript in order to improve maintenance. Below is a snippet from my sw.js file:
/* eslint-disable no-console */
self.addEventListener("push", (event) => {
...
});
...more handlers
Issue
While I have made many changes to comply with TS and ESLint requirements, I am facing an issue with the usage of self
. ESLint is flagging two errors:
unexpected use of 'self'
self is not defined
How can I properly define 'self' in a TypeScript file?