Here is my unique interface:
interface MeetingAttributeRecords {
branches: Array<Promise<any>>;
worshipStyles: Array<Promise<any>>;
accessibilities: Array<Promise<any>>;
}
Below is a simplified version of my specific controller:
export const getAllMeetings = async (req, res) => {
const meetings = await query(
`SELECT * FROM meeting;`
);
const promises: MeetingAttributeRecords = getMeetingAttributeRecords(meetings);
Promise.all([
Promise.all(promises.worshipStyles),
Promise.all(promises.branches),
Promise.all(promises.accessibilities)
]).then(() => {
res.json({ meetings: meetings.rows });
});
};
Also, here is the utility function that conducts additional queries and returns promises:
export async function getMeetingAttributeRecords(meetings) {
const branches = await meetings.rows.map(async (meeting) => {
const branch = await query(
// SQL CODE
);
return meeting.branch = branch.rows;
});
const worshipStyles = await meetings.rows.map(async (meeting) => {
const ws = await query(
// SQL CODE
);
return meeting.worship_style = ws.rows;
});
const accessibilities = await meetings.rows.map(async (meeting) => {
const access = await query(
// SQL CODE
);
return meeting.accessibility = access.rows;
});
return [branches, worshipStyles, accessibilities];
}
I am encountering the following Typescript errors:
[ts]
Type 'Promise<any[]>' is not assignable to type 'MeetingAttributeRecords'.
Property 'branches' is missing in type 'Promise<any[]>'.
I have been researching extensively but haven't found a solution yet. Any insight would be greatly appreciated!
If you require any further details, please do let me know!