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

Incorrect TS Typings In Service Worker #2858

Closed
greyscaled opened this issue Mar 10, 2021 · 4 comments
Closed

Incorrect TS Typings In Service Worker #2858

greyscaled opened this issue Mar 10, 2021 · 4 comments
Assignees
Labels
chore Related to maintenance or clean up enhancement Some improvement that isn't a feature
Milestone

Comments

@greyscaled
Copy link
Contributor

greyscaled commented Mar 10, 2021

Context

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((self as any).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

See Also

@greyscaled greyscaled added enhancement Some improvement that isn't a feature needs-investigation This issue needs to be further investigated labels Mar 10, 2021
@jsjoeio
Copy link
Contributor

jsjoeio commented Mar 10, 2021

Yeah the ideal solution would be fantastic if it works out. These issues may also help as a reference:

@greyscaled
Copy link
Contributor Author

@jsjoeio - I'll promise this one for the first milestone in June (see #2760 )

@greyscaled greyscaled added this to the v3.9.4 milestone Apr 30, 2021
@greyscaled greyscaled self-assigned this Apr 30, 2021
@jsjoeio jsjoeio modified the milestones: v3.9.4, v3.9.5 May 4, 2021
@jsjoeio
Copy link
Contributor

jsjoeio commented May 4, 2021

Moving to v3.9.5 since we're planning to cut v3.9.4 sooner than June.

@jsjoeio jsjoeio added the chore Related to maintenance or clean up label May 14, 2021
@code-asher code-asher modified the milestones: v3.10.1, 3.11.0 May 17, 2021
@jsjoeio jsjoeio modified the milestones: 3.10.2, 3.11.0 May 21, 2021
@jsjoeio jsjoeio modified the milestones: 3.11.0, 3.12.0 Jul 19, 2021
@jsjoeio jsjoeio modified the milestones: 3.12.0, On Deck Sep 9, 2021
@stale
Copy link

stale bot commented Mar 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.

@stale stale bot added the stale label Mar 8, 2022
@stale stale bot closed this as completed Mar 14, 2022
@code-asher code-asher removed the needs-investigation This issue needs to be further investigated label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Related to maintenance or clean up enhancement Some improvement that isn't a feature
Projects
None yet
Development

No branches or pull requests

3 participants