hmil / tslint-override

TSLint plugin bringing support for the override keyword
MIT License
27 stars 6 forks source link

`window` cannot be found inside of Web Workers #33

Closed wSedlacek closed 4 years ago

wSedlacek commented 4 years ago

When registering the decorators it is assumed that if global is undefined then window must be defined. However this is not always the case. In Web Workers global and window throw the following error (at least under TypeScript)

Error: apps/samples/basic/src/app/app.worker.ts:3:1 - error TS2304: Cannot find name 'window'.
Error: apps/samples/basic/src/app/app.worker.ts:4:1 - error TS2304: Cannot find name 'global'.

globalThis is defined however.

I know we did look at globalThis back when setting up the angular-register and we decided not to because of backwards compatibility. Maybe we should look at using/creating a globalThis polyfill so we can use globalThis instead of window or global and support Web Workers

Here is one such pollyfill I found: https://www.npmjs.com/package/globalthis

Another solution may be to simply offer an import that isn't attached to the global for cases like this.

wSedlacek commented 4 years ago

After further research it appears that self may be the way to go: https://developer.mozilla.org/en-US/docs/Web/API/Window/self