Skip to content

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

src/service.ts · focus
export class RequestHandler { constructor(private readonly store: TaskStore) {} handle(): void { this.store.handle(); } }

After

Implement the service port

src/service.ts · focus
interface Handler { handle(): void }
export class RequestHandler implements Handler { constructor(private readonly store: TaskStore) {} handle(): void { this.store.handle(); } }

Message IDs

requireInterface

Formerly: require-interface-for-injected-service