'TS Types for Google Calander API
So was experimenting with the Google Calendar API and working on it with TS. However, I can't seem to find a proper type for most of its functions. I do know that the API was built with TS and therefore should support it. But the more I search the more I run into various typefaces to install.
At the moment I've found the following typefaces (and they've been working so far)
- @types/gapi
- @types/gapi.auth2
- @types/gapi.client.calendar
My issue come with the calendar.event.insert() function. According to the guide in the documentation, you are supposed to include the following object properties:
export function listEvents(auth: OAuth2Client, eventData?: EventData) {
const calendar = google.calendar("v3");
addEvents(auth, calendar, eventData); // Add events
removeEvents(auth, calendar); // Remove events
}
function addEvents(auth: OAuth2Client, calendar: calendar_v3.Calendar, eventData: EventData) {
const addData = JSON.stringify(eventData);
console.log("adddata: ", addData);
calendar.events.insert(
{
auth: auth,
calendarId: "primary",
resources: addData,
},
function (err, res) {
if (err) {
console.log("Error: " + err);
return;
}
console.log(res);
}
);
}
However, as I do, I get an error claiming
"No overload matches this call."
With the types installed, it seems to identify the function as being of type "Params$Resource$Events$Insert" which apparently is not supposed to have a "resources" property.
The "eventData" is defined like this:
interface EventData {
summary: string;
location: string;
description?: string;
start: Time;
end: Time;
attendees: [];
reminders?: Notifications;
}
interface Time {
dateTime: Date;
timeZone: string;
}
interface Notifications {
useDefault: boolean;
overrides: NotificationOptions[];
}
interface NotificationOptions {
method: string;
minutes: number;
}
I'm guessing my types are either faulty or outdated compared to the latest API, but they are the latest versions. Any clue as to where one might find the proper types?
As you may notice in my addEvents() I have structured it according to the quick start guide for node in the Google Calendar API documention. In my listEvents() you'll also notice the calendar is called using google.calendar("v3") call (with google being an instance of googleapis)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|