Runtime - Service Worker
Configure TypeScript for browser service workers by loading the WebWorker libraries alongside ESNext modules and bundler resolution.
Why Use This Preset?
- Adds the
WebWorkerandWebWorker.Iterablelibraries so service-worker globals likeself,caches, andfetchevents type-check correctly. - Sets
ESNextmodules withBundlerresolution so imports match how your bundler ships the worker. - Targets the
ESNextlibrary so you can use the latest language features supported by the worker context. - Layers cleanly after
dx-essentialsanddx-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
{
"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.
| Setting | Value | Description |
|---|---|---|
lib | ["ESNext", "WebWorker", "WebWorker.Iterable"] | Exposes the latest ECMAScript APIs plus worker globals and async iterables. |
module | ESNext | Emits modern ECMAScript module syntax for the bundler to consume. |
moduleResolution | Bundler | Resolves 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.
Related
- Review the layering order in TSConfig Best Practices.
- See how presets compose end to end in the Presets Overview.