79654852

Date: 2025-06-05 16:26:24
Score: 1.5
Natty:
Report link

As it turned out it was so easy! )

@Injectable({
  providedIn: 'root'
})
export class JsonPlaceholderService implements BaseDataService  {
  get(): Observable<any> {};
}

@Injectable({
  providedIn: 'root',
  useClass: JsonPlaceholderService
})
export class BaseDataService implements IDataService {
  get(): Observable<any> {
    throw new Error('Method not implemented.');
  }
}

export interface IDataService {
  get(): Observable<any>;
}

And then we can use it as a dependency in a @Component()

  #jsonPlaceholderService = inject(BaseDataService);

No providers array in a @Component or AppConfig. So this way, our dependency is tree-shakable.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Component
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Alex Lavrik