Skip to content

Duplicate Interfaces Example

duplicate-interfaces-example/
├── services/
│ ├── INotificationService.ts
│ ├── EmailNotificationService.ts
│ ├── SmsNotificationService.ts
│ └── PushNotificationService.ts
├── ioc.config.json
└── README.md
export interface INotificationService {
sendNotification(message: string, recipient: string): Promise<void>;
getServiceName(): string;
}
export class EmailNotificationService implements INotificationService {
async sendNotification(message: string, recipient: string): Promise<void> {
console.log(`Sending EMAIL notification to ${recipient}: ${message}`);
await new Promise(resolve => setTimeout(resolve, 100));
}
getServiceName(): string {
return 'Email Notification Service';
}
}
export class SmsNotificationService implements INotificationService {
async sendNotification(message: string, recipient: string): Promise<void> {
console.log(`Sending SMS notification to ${recipient}: ${message}`);
await new Promise(resolve => setTimeout(resolve, 50));
}
getServiceName(): string {
return 'SMS Notification Service';
}
}
export class PushNotificationService implements INotificationService {
async sendNotification(message: string, recipient: string): Promise<void> {
console.log(`Sending PUSH notification to ${recipient}: ${message}`);
await new Promise(resolve => setTimeout(resolve, 25));
}
getServiceName(): string {
return 'Push Notification Service';
}
}
{
"source": ".",
"output": "container.gen.ts",
"interface": "I[A-Z].*",
"exclude": [
"**/*.test.ts",
"**/*.spec.ts"
],
"verbose": true,
"modules": {
"DuplicateModule": [
"services/**"
]
}
}
Error: Interface 'INotificationService' is implemented by multiple classes:
- EmailNotificationService (/path/to/services/EmailNotificationService.ts)
- SmsNotificationService (/path/to/services/SmsNotificationService.ts)
- PushNotificationService (/path/to/services/PushNotificationService.ts)
Multiple classes implement the same interface(s): INotificationService.
Each interface should only be implemented by one class for proper dependency injection.