Hey there! I'm currently working on an AngularJS project in TypeScript that involves integrating Google API to fetch Google Calendar events. The syntax for making a call is specified in the documentation available at: https://developers.google.com/google-apps/calendar/v3/reference/events/list. However, I encountered an issue where the
gapi.client.calendar.events.list(params)
method does not seem to accept the parameter orderBy: 'startTime'
getCalendarEvents() {
return gapi.client.calendar.calendarList.list().then(response => {
let calendars = response.result.items;
if (calendars === undefined) return [];
console.log(calendars);
let requests = calendars.map(calendar => {
//let params = { calendarId: calendar.id, timeMin: (new Date()).toISOString(), showDeleted: false, singleEvents: true, maxResults: 10 };
let params = {
calendarId: calendar.id,
timeMin: (new Date()).toISOString(),
showDeleted: false,
singleEvents: true,
orderBy: 'startTime' };
return gapi.client.calendar.events.list(params).then(response => {
console.log(response.result.items);
let events: any = response.result.items.sort((a, b) => { // sorting array of events by date
if (a.start.date) a.start['newdate'] = a.start.date;
if (b.start.date) b.start['newdate'] = b.start.date;
if (a.start.dateTime) a.start['newdate'] = a.start.dateTime.slice(0, 10);
if (b.start.dateTime) b.start['newdate'] = b.start.dateTime.slice(0, 10);
if (a.start['newdate'] > b.start['newdate']) return 1;
if (a.start['newdate'] < b.start['newdate']) return -1;
return 0;
});
return events.map(event => {
let calendarEvent: CalendarEvent = {
title: event.summary,
htmlLink: event.htmlLink,
start: new Date(event.start.date == undefined ? event.start.dateTime == undefined ? '' : event.start.dateTime : event.start.date),
end: new Date(event.end.date == undefined ? event.end.dateTime == undefined ? '' : event.end.dateTime : event.end.date),
allDay: false,
color: calendar.backgroundColor
};
return calendarEvent;
});
});
});
return this.$q.all(requests);
});
}
Can anyone help me with why this isn't functioning as expected?
file: 'file:///d%3A/Projects/Homepage2/app/google.service.ts' severity: 'Error' message: 'Argument of type '{ calendarId: string; timeMin: string; showDeleted: boolean; singleEvents: boolean; orderBy: stri...' is not assignable to parameter of type 'EventsListParameters'. Types of property 'orderBy' are incompatible. Type 'string' is not assignable to type '"startTime" | "updated" | undefined'.' at: '166,61' source: 'ts'
The 'params' object is defined as follows:
interface EventsListParameters {
calendarId: string;
alwaysIncludeEmail?: boolean;
iCalUID?: string;
maxAttendees?: integer;
maxResults?: integer;
orderBy?: EventsOrder;
pageToken?: string;
privateExtendedProperty?: string;
q?: string;
sharedExtendedProperty?: string;
showDeleted?: boolean;
showHiddenInvitations?: boolean;
singleEvents?: boolean;
syncToken?: SyncToken;
timeMax?: datetime;
timeMin?: datetime;
timeZone?: string;
updatedMin?: datetime;
}
And here is how 'EventsOrder' is defined:
type EventsOrder =
// Order by the start date/time (ascending). This is only available when querying single events (i.e. the parameter singleEvents is True)
'startTime' |
// Order by last modification time (ascending).
'updated';