Repository navigation
Description
Describe the problem that you experienced
The documentation for SwRegistrationOptions is internally inconsistent about what it is, and the way it's presented encourages a pattern that violates the expectations the class keyword creates for readers — a disconnect surfaced by the new typescript-eslint rule @typescript-eslint/no-unsafe-class-instance-assignment.
Specifically:
-
The getting-started guide calls
SwRegistrationOptionsan interface:Angular service workers support comprehensive configuration options through the
SwRegistrationOptionsinterface […] -
The API reference page for the same name declares it as an
abstract class:abstract class SwRegistrationOptions { enabled?: boolean | undefined; updateViaCache?: ServiceWorkerUpdateViaCache | undefined; type?: WorkerType | undefined; scope?: string | undefined; registrationStrategy?: string | (() => Observable<unknown>) | undefined; }
-
Both pages then demonstrate passing plain object literals where this abstract class type is expected — e.g.
provideServiceWorker('ngsw-worker.js', { enabled: !isDevMode(), scope: '/app/' })— which only compiles because TypeScript assigns classes structurally, ignoring the class-ness the declaration implies to readers.
A reader who sees a class (abstract or not) reasonably expects class semantics: derived behavior via getters, constructor logic/invariants, subclassing, instanceof. Nothing here is intended to work that way — it is documented and used purely as a structural shape, with the class/abstract form serving only to make the type usable as a legacy DI provider token ({ provide: SwRegistrationOptions, useFactory: ... }).
Enter the URL of the topic with the problem
- https://angular.dev/api/service-worker/SwRegistrationOptions
- https://angular.dev/ecosystem/service-workers/getting-started#service-worker-configuration
Describe what you were looking for in the documentation
I was looking for the correct way to pass registration options to provideServiceWorker() and for a precise definition of what SwRegistrationOptions is (interface vs. class), so I could judge whether the documented pattern is safe to use under strict type-checking and linting (typescript-eslint with type-checked rules, including the newly added no-unsafe-class-instance-assignment, which flags object literals assigned where a class instance is expected).
Describe the actions that led you to experience the problem
- Followed the getting-started guide and added the documented
provideServiceWorker('ngsw-worker.js', { enabled: ..., scope: ... })call to my app config. - Enabled the new typescript-eslint rule
@typescript-eslint/no-unsafe-class-instance-assignment. - The documented pattern was flagged: an object literal is passed where an instance of the (abstract) class
SwRegistrationOptionsis expected. - Checked the two documentation pages linked above and found one calls the type an "interface" while the other declares it an
abstract class.
Describe what you want to experience that would fix the problem
Any of the following would resolve it, in descending order of preference:
- API change (root cause): Declare
SwRegistrationOptionsas aninterfaceand, if the legacyprovide: SwRegistrationOptionsDI usage must keep working, keep a class/token only for that purpose — or migrate that example to a modernInjectionToken<SwRegistrationOptions>. That would make the documentedprovideServiceWorker(..., { ... })pattern fully consistent with the declared type. - Docs-only fix (minimal): Make the two pages agree on what the type is, and explicitly document that
SwRegistrationOptionsis intentionally declared as anabstract classsolely so it can serve as a DI token, that instances are never constructed, and that plain object literals are the supported (and expected) way to supply options — so readers and linters don't misinterpret it as a class with instance semantics.
Add a screenshot if that helps illustrate the problem
N/A — the discrepancy is textual between the two linked pages.
If this problem caused an exception or error, please paste it here
/PATH_TO_MY_PROJECT/src/app/app.config.ts
37:7 error This object literal is used where an instance of class `SwRegistrationOptions` is expected @typescript-eslint/no-unsafe-class-instance-assignment
(Rule docs: https://typescript-eslint.io/rules/no-unsafe-class-instance-assignment — "reports values that aren't created by a class's constructor but are used where an instance of the class is expected".)
If the problem is browser-specific, please specify the device, OS, browser, and version
Not browser-specific.
Provide any additional information here in as much as detail as you can
- TypeScript's structural assignability means any object literal satisfying the public member shape passes even when the target is a class; the new eslint rule treats class-provenance as a nominal signal instead. Angular's own API only works under the structural interpretation, while the
classdeclaration signals instance semantics to readers — the two interpretations conflict, and the docs sit on both sides of the fence (calling it an "interface" on one page while declaring anabstract classon the other). - The
abstractmodifier suggests the class exists mainly to preventnew SwRegistrationOptions()while remaining usable as a DI token (the API page shows exactly that legacy usage in its Description section). That's a reasonable legacy constraint, but it should be stated, or the design should move tointerface+InjectionToken. - Reference to the eslint rule's own "When Not To Use It" guidance, which describes this exact situation as an anti-pattern to avoid declaring: "If you use classes as plain shapes, such as data containers whose constructors don't do anything important, you might prefer to declare those shapes as interfaces or type aliases instead."
- Verified against angular.dev at v22.3.0 (site footer) as of 1 Dec 2026.
- Everything above this bullet point was drafted with the assistance of an AI assistant. I read every single word to confirm that I wouldn't be annoyed if I received this report.
Activity