Skip to content

ClientOptions doesn't accept the getClient instance from new GoogleAuth.getClient() in TypeScript #258

@jonaslalin

Description

@jonaslalin

Environment details

  • OS: macOS 13.1 (22C65)
  • Node.js version: v18.12.0
  • npm version: 8.19.2
  • google-gax version: 3.5.2
  • google-auth-library version: 8.7.0
  • @google-cloud/aiplatform version: 2.3.0
  • typescript version: 4.9.4

Steps to reproduce

I want to create a google auth client and pass it to services in @google-cloud/aiplatform, for example using the JobServiceClient. I get an incompatible type error from TypeScript, see below. JobServiceClient is using ClientOptions from google-gax.

import { JobServiceClient } from "@google-cloud/aiplatform";
import { GoogleAuth } from "google-auth-library";
import { ClientOptions } from "google-gax";

const googleAuth = new GoogleAuth({
    scopes: "https://www.googleapis.com/auth/cloud-platform",
});
const googleAuthClient = await googleAuth.getClient();

const clientOptions: ClientOptions = {
    authClient: googleAuthClient,
};

const jobServiceClient = new JobServiceClient(clientOptions);

throws

TS2322: Type 'Compute | JSONClient' is not assignable to type 'JSONClient'.
  Type 'Compute' is not assignable to type 'JSONClient'.
    Type 'Compute' is missing the following properties from type 'JWT': createScoped, hasUserScopes, hasAnyScopes, authorize, and 7 more.

11     authClient: googleAuthClient,
       ~~~~~~~~~~

  node_modules/google-auth-library/build/src/auth/googleauth.d.ts:38:5
    38     authClient?: T;
           ~~~~~~~~~~
    The expected type comes from property 'authClient' which is declared here on type 'ClientOptions'

Metadata

Metadata

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions