title: Angular: Using TypeScript for Service Worker (ServiceWorkerModule)
body: <p>Is it possible to register a ServiceWorker written in TypeScript with <code>@angular/service-worker</code>?</p>
  
  <p>currently registering a service worker looks like this in <strong>app.module.ts</strong>:</p>
  
  <pre><code>ServiceWorkerModule.register('ngsw-worker.js', {
    enabled: environment.production
  })
  </code></pre>
  
  <p>Is it somehow possible to register a <code>ngsw-worker.ts</code>?</p>
  
  <p>At least this is possible with web workers in Angular:</p>
  
  <pre><code>const worker = new Worker('../my-worker.worker', {
        type: 'module'
      });
  </code></pre>
  
  <p><em>my-worker.worker.ts</em></p>
  
  <pre><code>/// &lt;reference lib="webworker" /&gt;
  
  import {someMethod} from './some-method';
  
  addEventListener('message', ({ data }) =&gt; {
    const response = `worker response to ${data}`;
    postMessage(response);
    someMethod();
  });
  </code></pre>
  
  <p>Any help is appreciated - thanks</p>