I try to use a diferent type of declaration for my object “docs”, because i want to use the same Interface “ResponseInterface” for differents requests, one is for User[] and other is for Hospitals[] or whatever.
the thing is that i want to use the same declarations of baseResponseInterface in HospitalInterface & UserInterface sharing the “docs” for the different request or type of elements.
i haven’t achieved that.
I’ve follow some steps that i found with this:
In my response.interface.ts file:
export type ResponseInterface = UserInterface | HospitalInterface;
interface baseResponseInterface {
totalPages: number,
page: number,
hasNextPage: boolean,
hasPrevPage: boolean,
nextPage: number | null,
prevPage: number | null,
limit: number,
pagingCounter: number,
totalDocs: number,
}
interface HospitalInterface extends baseResponseInterface{
docs: HospitalInterfacee[]
}
interface UserInterface extends baseResponseInterface{
docs: User[],
}
in my components.ts i declare my interface with this
public response: ResponseInterface | undefined;
but in the html code i get this error message:
<tr *ngFor="let user of response?.docs; let index = index">
...
</tr>
enter image description here
Could someone help me with this? Is it possible?
Or i need to create an own Interface for each type of response?
UserResponseInterface & HospitalResponseInterface?
Adrian Rojas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.