I am trying to add a new array item to the start of an existing array and get an error. I am trying to add a new array item to the array that is constructed on the fly. The example code below causes an error using the unshift operation.
The array that I want to insert to is lRtn.document.mainTemplate.item.items and I am using lodash to iterate over the parameter _pUrls and for each url I am creating a new array item and want to push the new array item to the existing array lRtn.document.mainTemplate.item.items leaving the existing array content in place.
The error is get is
Argument of type '{ type: string; description: string; source: any; }' is not assignable to parameter of type '{ type: string; duration: number; contentType?: undefined; content?: undefined; } | { type: string; contentType: string; content: string; duration?: undefined; }'.
Type '{ type: string; description: string; source: any; }' is missing the following properties from type '{ type: string; contentType: string; content: string; duration?: undefined; }': contentType, content
The code that I have tried is here below, any help or guidance would be much appreciated.
export async function createAPLADirectiveBookReviews(
_pUrls: any,
_pFollowOn: string,
) {
const lDescription = 'review';
const lRtn = {
type: constants.APLA.directiveType,
token: constants.APLA.token,
document: {
version: '0.91',
type: 'APLA',
description: 'This document demonstrates key components used to create audio responses.',
mainTemplate: {
parameters: ['payload'],
item: {
type: 'Sequencer',
description: 'Play this audio back in sequence',
items: [
{
type: 'Silence',
duration: 1500,
},
{
type: 'Speech',
contentType: 'PlainText',
content: _pFollowOn,
},
],
},
},
},
datasources: {
},
};
// iterate over the urls and add them to the list
_.forEach(_pUrls, function (url) {
let lArrayItem = { 'type': 'Audio', 'description': lDescription, 'source': url };
lRtn.document.mainTemplate.item.items.unshift(lArrayItem);
});
return lRtn;
}