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

Getting type of property of object in array

You can obtain the type of a property of an object in in typescript as follows:

interface Person {
    name: string;
    realEstate: {
        street: string;
        value: number;
    }[]

}
let mrName: Person['name']

Is there any way to obtain the type of street and value?

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

>Solution :

Have you tried this way?

let streetType : Person['realEstate'][0]['street'];

let street : typeof streetType = "Hale";

console.log(street);

let valueType : Person['realEstate'][0]['value'];

let value : typeof valueType = 10000;

console.log(value);
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