Skip to content

require-interface-for-exported-class

Require exported concrete classes with public behavior to declare a contract.

Why

An explicit contract names the intended public capability separately from implementation details. TypeScript already supports structural compatibility; this is an architecture policy, not a prerequisite for substitution.

Fix

Declare a focused interface and add an implements clause, or inherit from an intentional base contract.

Examples

Before — flagged Do not export behavior only through a concrete class
src/artifact-store.ts
export class ArtifactStore {
async read(id: string) {
return new Uint8Array();
}
}
After — preferred Export behavior through a focused contract
src/artifact-store.ts
export interface ArtifactStorage {
read(id: string): Promise<Uint8Array>;
}
export class ArtifactStore implements ArtifactStorage {
async read(id: string) {
return new Uint8Array();
}
}