Q:

How to get class function from a service that return a model

I'm having a class (userName) which its properties defined a model (casting from json).
This class has also a simple function that return the full Name:
export class userName {
    firstName: string;
    lastName: string;
    get fullName() {
     return `${this.firstName} ${this.LastName}`
    }

I have a service that return a collection of users:
getUsers() : Observable<userName[]>
{
 return this.http.get<userName[]>(<path>);
}

Now - I get the collection from the service into the component. When I iterate the collection, I want to get the firstName + LastNamne just like the fullName property does, but it's not part of the model that the service return. Is there a way reaching it without creating my own extension ? 

A:

Class:
export class userName {
  firstName: string;
  lastName: string;
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }

  constructor(firstName: string, lastName: string) {
    Object.assign(this, { firstName, lastName });
  }
}

Service:
getUsers() : Observable<userName[]> {
    return this.http.get<userName[]>(<path>).pipe(map((user: userName) => new userName(user.firstName, user.lastName));
  }

