I'm currently working on a TypeScript application and I've run into an issue with assigning values. Here are the interfaces for reference:
export interface SearchTexts {
SearchText: SearchText[];
}
export interface SearchText {
Value: string;
BusinessID: string;
}
This is how you should assign the values:
let searchTextArr: SearchText[] = [];
const invoiceNumbers: string[] = ["INV4587965", "INV4589654"];
for (var index in invoiceNumbers) {
let searchText: SearchText = {
Value: invoiceNumbers[index],
BusinessID: "BSD458"
};
searchTextArr.push(searchText);
}
let searchItems: SearchTexts;
searchItems.SearchText = searchTextArr; //Encountering error during assignment
The error message is as follows:
(node:17661) UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'SearchText' of undefined
I have used console.log to check if searchTextArr contains values, and it does. However, I am still unable to pinpoint the issue. If anyone can help me identify where the problem lies, I would greatly appreciate it.