Skip to content

TypeScript issue: Type 'JSONClient | Compute' is not assignable to type 'JSONClient' #779

@therealgilles

Description

@therealgilles

I am trying to find the proper type for auth.getClient() in the code below:

let authClient: import('google-auth-library/build/src/auth/googleauth').JSONClient

const sheets = async (): Promise<sheets_v4.Sheets> => {
        try {
          if (!authClient) {
            // create a new JWT client using the key file downloaded from the Google Developer Console
            const auth = new google.auth.GoogleAuth({
              keyFile: ...,
              scopes: ...,
            })
            authClient = await auth.getClient()
          }

          return google.sheets({ version: 'v4', auth: authClient })
        } catch (err) {
          error(err)
          throw new Error(err)
        }

It seems it should be JSONClient but having to access the type through an import seems odd and then I get the following error:

Type 'JSONClient | Compute' is not assignable to type 'JSONClient'

Some advice/guidance would be appreciated.

Metadata

Metadata

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions