From b835f02ad76596ffd91e2b60fad6a05cb546d619 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 21 Nov 2025 20:54:26 +0000 Subject: [PATCH] fix(calendar): resolve type errors Resolved TypeScript type errors in the calendar/quickstart/quickstart.gs file. - Added JSDoc `@typedef` for CalendarEvent and CalendarEventDateTime to define the object structures. - Added a check to ensure the Calendar advanced service is enabled. - Cast the error object in the catch block to the Error type. - Added checks for undefined `events` and `event.start` to prevent runtime errors. --- calendar/quickstart/quickstart.gs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/calendar/quickstart/quickstart.gs b/calendar/quickstart/quickstart.gs index 026aedc6d..5c79bf38e 100644 --- a/calendar/quickstart/quickstart.gs +++ b/calendar/quickstart/quickstart.gs @@ -14,11 +14,28 @@ * limitations under the License. */ // [START calendar_quickstart] +/** + * @typedef {Object} CalendarEventDateTime + * @property {string} [dateTime] + * @property {string} [date] + */ + +/** + * @typedef {Object} CalendarEvent + * @property {string} summary + * @property {CalendarEventDateTime} start + */ + /** * Lists 10 upcoming events in the user's calendar. + * @return {void} * @see https://developers.google.com/calendar/api/v3/reference/events/list */ function listUpcomingEvents() { + // Add a check for the Calendar advanced service. + if (!Calendar.Events) { + throw new Error('Please enable the Calendar advanced service.'); + } const calendarId = 'primary'; // Add query parameters in optionalArgs const optionalArgs = { @@ -33,12 +50,15 @@ function listUpcomingEvents() { // call Events.list method to list the calendar events using calendarId optional query parameter const response = Calendar.Events.list(calendarId, optionalArgs); const events = response.items; - if (events.length === 0) { + if (!events || events.length === 0) { console.log('No upcoming events found'); return; } // Print the calendar events - for (const event of events) { + for (const event of /** @type {CalendarEvent[]} */ (events)) { + if (!event.start) { + continue; + } let when = event.start.dateTime; if (!when) { when = event.start.date; @@ -47,7 +67,7 @@ function listUpcomingEvents() { } } catch (err) { // TODO (developer) - Handle exception from Calendar API - console.log('Failed with error %s', err.message); + console.log('Failed with error %s', /** @type {Error} */ (err).message); } } // [END calendar_quickstart]