Skip to content Skip to sidebar Skip to footer

Typeerror: .currentpizzaplace.getpoint Is Not A Function

TypeError: this.pizzaPlaceEditService.currentPizzaPlace.getPoint is not a function I found TypeError: is not a function typescript class but I don't think it applies to this situat

Solution 1:

Thanks to Artem's excellent input, I was able to figure out that the problem was caused by the fact that I was creating an object from the JSON instead of the object that I wanted and so it was a different type. Evidently, Classes in Typescript are compile time only and are discarded at runtime.

So, based on: How do I initialize a TypeScript object with a JSON object option 4 of the selected answer, I created a serializable.ts.

export interface Serializable<T> {
  deserialize(input: Object): T;
}

And then modified my class with the implements:

exportclassPizzaPlaceimplementsSerializable<PizzaPlace> {

and then added:

  deserialize(input): PizzaPlace {
    this.paypalAccount = input.paypalAccount;
    this.customerId = input.customerId;
    ...
    this.settings = input.settings;

    returnthis;
  }

Then, since my web service returns an array of these, I changed my service call:

  .subscribe(places =>this.deserializePlaces(places));

and added a new function:

deserializePlaces(places: Object[]){
    this.pizzaPlaces = [];

    places.forEach(obj=> {
      let place = newPizzaPlace().deserialize(obj);
      this.pizzaPlaces.push(place);
    });
  }

And this seems to work just fine. Thanks for the input.

Post a Comment for "Typeerror: .currentpizzaplace.getpoint Is Not A Function"