title: Why is undefined returned when accessing properties of a typescript object in an angular2 project?
body: <p>I have an angular2 project in which I am using the http module to make a get request. The object is retrieved from the server and apparently is deserialized properly into its corresponding typescript object, but when I try to access a property it returns undefined, even though when I print the object to the console right before trying to access these properties, the data appears to exist.</p>
  
  <p>This is what my get request method looks like.</p>
  
  <pre><code>  getDataForEmployee(data){
      var url = this.active+"/guest/"+data;
  
      var headers = new Headers();
  
      headers.append("Content-Type", "application/json");
  
      return this.http
        .get(url, {headers:headers})
        .toPromise()
        .then((res:Response)=&gt; res.json() as Employee);
  
    }
  </code></pre>
  
  <p>This is how the method looks which is handling the response.</p>
  
  <pre><code>this.employeeHttp.getDataForEmployee(userid)
    .then((employee:Employee)=&gt;{
      console.log(employee);
      console.log("firstname: "+employee.firstName);
      ...
  </code></pre>
  
  <p>The Employee class looks like this:</p>
  
  <pre><code> export class Employee {
  
      ...
        private _firstName:string;
      ...
  
        get firstName(): string {
          return this._firstName;
        }
  
        set firstName(value: string) {
          this._firstName = value;
        }
  
      ...
      }
  </code></pre>
  
  <p>The image shows the console output when making this request.
  <a href="https://i.stack.imgur.com/7VVbd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7VVbd.png" alt="Image of the console output"></a></p>
  
  <p>I don't understand why when I try to retrieve firstName it returned undefined even though it exists in the object right before.</p>
  
  <p>Any ideas as to why this is happening would be very helpful to me.</p>