11
lorentz
3y

How the fuck does TypeScript still not have service worker support? Seriously, it's just a typings file. People have written that typings file. They would just have to include it in the lib collection shipped with the compiler. Yeah, it would have DOM calls intermixed with the SW api, but frankly, having the typings for a set of calls you can't use is infinitely better than missing them for a set of calls you can.
The relevant issue is 5 years old btw.

Comments
  • 3
    You just answered your own question.

    And having it in lib doesn’t make sense if you setup a tsconfig just for service workers since that code should purposefully be as short as possible.

    This is intended and most likely won’t ever be fixed - because it doesn’t fit to the goal of typescript.
  • 1
    @petergriffin I don't understand why I couldn't have them in lib? Even if my service workers are as small as possible I could have a separate tsconfig. Tsconfigs are free. And if not (maybe because it's a simpler project and I don't want multiple configs), I could include it in lib and just ignore the global objects when I'm not writing for a worker. It's not like I use objects without knowing what they do and when they're available. And finally, Typescript added template types just to accommodate dumb APIs, how would service workers, an environment available as part of every browser and hopefully soon used in every webapp not fit their goal?
  • 7
    Service workers have been shot off the roadmap because they are racist, colonial, sexist, and misogynist.
  • 4
    @Fast-Nop So when will the "unpaid intern" spec be released?
  • 5
    @homo-lorens Its "paid intern", paid with experience.
  • 1
    Btw I figured it out but it's not really possible to do it without typescript reference tags because you have to disable the default lib for ServiceWorkerGlobalScope to exist for whatever fucked up reason.
  • 1
    Update: the "worker" lib is accessible only if you unload the standard library, and unloading the standard library can only be done project wide. It is literally not possible to access ServiceWorkerGlobalScope from any file without forfeiting access to Window from all files. This is a huge design problem as any typescript project that includes a service worker likely also includes code that needs Window, since that's where you load service workers.
    I have copied the lib.worker.d.ts file from my distribution of Typescript into the custom typings folder and edited it to get along with the standard library.
Add Comment