In the process of developing a website with Angular4 and retrieving data from Contentful CMS API, I am encountering an issue with assigning proper types to the returned data despite seeing the correct types in the console.
The example mock data is as follows:
export const NAMES: Page[] = content.getEntries({
content_type: 'mainMenu'
}).then(function(response){
response.items.forEach(element => {
return element.fields;
})
});
When displayed in the console using console.log, the data appears like this:
Object { title: "About Aliens" }
Object { title: "Portfolio" }
Object { title: "Meet the team" }
Object { title: "Contact us" }
Here is the class I have used to assign these data types:
export class Page {
title: string;
}
Being new to Typescript, I am seeking guidance on where I may have gone wrong. Any assistance on mastering the handling of such data from any API would be greatly appreciated.
Thank you.