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
Rewrote the Service Worker in TypeScript! It *kind of* works great, but not quite. I wish the TypeScript team made tooling for Workers a bit better, as it seems harder to work with than it should be.
This rewrite was all from last night, and it took a few hours to learn how to get things right (I didn't get around to commiting it until now though). There aren't any type errors anymore, but I'm also unsure if it will run sucessfully yet. I don't have a device/OS to test the Web Share Target API support anymore, since my Chromebook runs Ubuntu now :)
While it's not fully functional yet, this is a step in the right direction for type-safe Service Worker code!
I mostly rewrote it with my new programming styles, expanding things out for readability, and making use of async-await where it was previously just `.then()` calls and such.
Some help to get it working:
https://github.com/NicholasPeretti/service-worker-ts-examplehttps://stackoverflow.com/questions/89332/how-do-i-recover-a-dropped-stash-in-git (I had an oopsie XD)
Edit:
Tried testing out the worker in the browser, and modern TypeScript now includes empty `export {}` instances in the resulting JS, which breaks declaring the file as a module, as you can't have `export {}` in a non-module script. The only way I got close to this was to name the file `.mts`, but I'm not sure if I like that or not. But hey, it may work. With that being a possible solution, I found all of these sources along the way also:
https://stackoverflow.com/questions/56356655/structuring-a-typescript-project-with-workershttps://github.com/jakearchibald/typescript-worker-example (now outdated, unfortunately, thanks to this new TypeScript change)
microsoft/TypeScript#41513https://www.devextent.com/create-service-worker-typescript/ (almost works! falls down to the same issue sadly)
microsoft/TypeScript#14877microsoft/TypeScript#11781
0 commit comments