Home > other >  Typescript and Map returning error message
Typescript and Map returning error message

Time:11-02

I have 2 interfaces that have the following properties

export interface parent{
   fName: string;
   addresses: Array<address>;
}

export interface address{
   street: string;
   city: string;
   state: string;
   zip: string;
}

In my code I load the parent class and the address properties from JSON.

When I try to retrieve the array of "street" properties, I use the following code.

var father = parent; var streets = father.map(x=>x.street);

I am receiving an error stating father.map is not a function.

What am I doing wrong?

CodePudding user response:

you need to write father.addresses.map(x=>x.street); since the array is the addresses property

  • Related