Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript and Map returning error message

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading