'Has anyone received this error when inserting a calendar event using the Google Calendar API? Related to BodyResponseCallback<Schema$Event> ts(2769)

I am coding in Typescript and trying to insert an event but I am getting this error that the body of what I am inserting "is not assignable to parameter of type 'BodyResponseCallback<Schema$Event>'." I have tried a few different things and even also seen tutorials do it this way but I don't think the error should be acceptable unless if it really is some bug in the source code? Does anyone see what may be the issue here? Thanks in advance. Please see the code and error message below.

router.post('/create-event', (req: CustomRequest, res, next) => {
  try {
    void (async () => {
      const { description, startDateTime, endDateTime } = req.body
      oAuth2Client.setCredentials({
        refresh_token:
          (hidden)
      })
      const calendar = google.calendar('v3')
      const response = await calendar.events.insert({
        auth: oAuth2Client,
        calendarId: 'primary',
        requestBody: {
          description: description,
          colorId: '7',
          start: {
            dateTime: new Date(startDateTime),
          },
          end: {
            dateTime: new Date(endDateTime),
          },
          // see req.body available properties that could help with timeagent
        },
      })
      res.send(response)
    })()
  } catch (error) {
    console.log(error)

    next(error)
  }
})

The "auth: oAuth2Client," is underlined in red and says:

(alias) const oAuth2Client: OAuth2Client import oAuth2Client

No overload matches this call.

Overload 2 of 6, '(callback: BodyResponseCallback<Schema$Event>): void', gave the following error.

Argument of type '{ auth: OAuth2Client; calendarId: string; requestBody: { description: string; colorId: string; start: { dateTime: Date; }; end: { dateTime: Date; }; }; }' is not assignable to parameter of type 'BodyResponseCallback<Schema$Event>'.

Object literal may only specify known properties, and 'auth' does not exist in type 'BodyResponseCallback<Schema$Event>'.ts(2769)



Solution 1:[1]

I solved this by adding { responseType: 'json' } as the second argument to the insert function. It seems like an issue with types in the SDK.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Vnenk