Skip to content

require-explicit-contract-implementation

Require nominal inheritance when an injected abstract class is rejected by an instanceof guard.

Why

A structurally assignable fake can still fail a constructor's nominal runtime guard. Pure structural interfaces do not require an implements clause.

Fix

Use an implementation inheriting the existing abstract class, or remove the nominal guard if the boundary is intentionally structural.

Examples

Before — flagged A structurally compatible fake fails the constructor's runtime guard
src/service.ts
abstract class Publisher {
abstract publish(): void;
}
class Consumer {
constructor(readonly publisher: Publisher) {
if (!(publisher instanceof Publisher))
throw new TypeError("Nominal publisher required");
}
}
class FakePublisher {
publish() {}
}
new Consumer(new FakePublisher());
After — preferred The fake satisfies the existing nominal runtime contract
src/service.ts
abstract class Publisher {
abstract publish(): void;
}
class Consumer {
constructor(readonly publisher: Publisher) {
if (!(publisher instanceof Publisher))
throw new TypeError("Nominal publisher required");
}
}
class FakePublisher extends Publisher {
publish() {}
}
new Consumer(new FakePublisher());