Skip to main content

Runtime - Service Worker

Configure TypeScript for browser service workers by loading the WebWorker libraries alongside ESNext modules and bundler resolution.

Why Use This Preset?

  1. Adds the WebWorker and WebWorker.Iterable libraries so service-worker globals like self, caches, and fetch events type-check correctly.
  2. Sets ESNext modules with Bundler resolution so imports match how your bundler ships the worker.
  3. Targets the ESNext library so you can use the latest language features supported by the worker context.
  4. Layers cleanly after dx-essentials and dx-strict, adding only the worker-specific type surface on top of your strictness baseline.

Usage

Add the preset to the extends array of your tsconfig.json, after the essentials and strict layers.

tsconfig.json
json
{
  "extends": [
    "@cbnventures/nova/presets/tsconfig/dx-essentials.json",
    "@cbnventures/nova/presets/tsconfig/dx-strict.json",
    "@cbnventures/nova/presets/tsconfig/runtime-service-worker.json"
  ]
}

What This Preset Configures

This preset sets the following compilerOptions.

SettingValueDescription
lib["ESNext", "WebWorker", "WebWorker.Iterable"]Exposes the latest ECMAScript APIs plus worker globals and async iterables.
moduleESNextEmits modern ECMAScript module syntax for the bundler to consume.
moduleResolutionBundlerResolves imports the way a bundler does, matching how the worker ships.

info

The lib array replaces the parent's value rather than merging with it, so this preset omits the DOM library that the main browser thread relies on but a worker context does not provide.