My API call returns a response in the following format:
export interface UserResponse {
id: string;
is_admin: boolean;
last_name: string;
phone: string;
...
salary: number;
}
After that, I use the datePipe transform
method to convert my date into a different format, which results in a string.
For example:
this.users[0].salary = this.currencyPipe.transform(this.users[i].salary, 'USD', 'symbol', '1.0-0');
Now, my salary is no longer a number but a string.
So, I created another model for users with salaries as strings instead of numbers -
with salary string but not number.
export interface User {
id: string;
is_admin: boolean;
last_name: string;
phone: string;
...
salary: string;
}
However, there are many repeated properties such as id, is_admin, etc.
How can I reuse them?
For instance, I'll create a third interface:
export interface UserBase {
id: string;
is_admin: boolean;
last_name: string;
phone: string;
}
Now, how can I insert all properties from UserBase
into User
and UserResponse
?
export interface User {
}