TypeScript · architecture
require-port-for-service
eslint:require-port-for-service Advise when an exported service with injected collaborators has public methods not covered by its declared ports.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
A declared port keeps consumers coupled to the service capability instead of its concrete implementation.
Fix
Declare and implement an interface covering the service's public methods.
Before / after
Executed by this rule’s unit tests.
Before
Do not expose only the concrete service
export class RequestHandler { constructor(private readonly store: TaskStore) {} handle(): void { this.store.handle(); } } After
Implement the service port
interface Handler { handle(): void }
export class RequestHandler implements Handler { constructor(private readonly store: TaskStore) {} handle(): void { this.store.handle(); } } Message IDs
requireInterfaceFormerly: require-interface-for-injected-service