You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the time of this writing, our service worker is very simple:
/* eslint-disable @typescript-eslint/no-explicit-any */self.addEventListener("install",()=>{console.log("[Service Worker] installed")})self.addEventListener("activate",(event: any)=>{event.waitUntil((selfasany).clients.claim())console.log("[Service Worker] activated")})self.addEventListener("fetch",()=>{// Without this event handler we won't be recognized as a PWA.})
However, with #2760 and any future/related efforts, the service worker will be growing in complexity and scope, as offline cached responses will be added.
Problem
Our service worker uses the same tsconfig as the rest of the project, and uses the any typing. What this amounts to are the following:
Perceived access to APIs that do not exist in the context of a service worker (lib.d.ts)
Lack of type safety on service worker, web worker global scope
Ideal Solution
Use a root, extendable tsconfig and separate tsconfig for the separate areas of the application - service worker, browser and node
Quick Solution
Use triple slash directives to remove lib.d.ts and add in the missing references
Context
At the time of this writing, our service worker is very simple:
However, with #2760 and any future/related efforts, the service worker will be growing in complexity and scope, as offline cached responses will be added.
Problem
Our service worker uses the same
tsconfig
as the rest of the project, and uses theany
typing. What this amounts to are the following:lib.d.ts
)Ideal Solution
Use a root, extendable
tsconfig
and separatetsconfig
for the separate areas of the application - service worker, browser and nodeQuick Solution
lib.d.ts
and add in the missing referencesSee Also
The text was updated successfully, but these errors were encountered: