I have a model that I load from an API to a typescript model
export class Customer{
constructor(
public customer_id: number,
public first_name: string,
public last_name: string,
public email_address: string,
public phone_number: number,
public user_name: string
) { }
}
And in the service I compare the users obtained from the API with their role to add the attributes of the Customer
import { Customer } from "../models/customer";
this.users.forEach(user => {
if(parseInt(user.role_id)===1){
let customerAux = this.customers.find((customerAux) => customerAux.user_name === user.name);
if(customerAux){
user.first_name = customerAux.first_name;
user.last_name = customerAux.last_name;
user.phone_number = customerAux.phone_number;
}
}
});
And it throws TS2339: Property ‘user_name’ does not exist on type ‘Customer’. [plugin angular-compiler]
I tried make a cast of type customer but it throws the same
New contributor
David Alvarado Barboza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.