DEV Community

Discussion on: Building a Firebase CRUD Service for Angular

Collapse
 
mytsu profile image
Jonathan Arantes

You can't access data.id if you're using a generic type, isn't better to use a abstract class?

Collapse
 
coly010 profile image
Colum Ferry

I missed a part of my total usage of this.

I create a base interface called Entity:

export interface Entity {
id: string;
}
Enter fullscreen mode Exit fullscreen mode

Then the Crud Type Generic should be

export class FirebaseCrudService<T extends Entity> {
...
}
Enter fullscreen mode Exit fullscreen mode

Then finally, all our models will extend the Entity interface

export interface Todo extends Entity {
...
}
Enter fullscreen mode Exit fullscreen mode