Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoogleAuth type should be generic GoogleAuth<T extends AuthClient> #3357

Open
edosrecki opened this issue Sep 28, 2023 · 1 comment
Open
Labels
api: sqladmin Issues related to the Cloud SQL Admin API API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@edosrecki
Copy link

I am trying to instantiate a Sqladmin class by passing a custom GoogleAuth object, which was in turn instantiated by passing a custom AuthClient object.

However, I get a TypeScript error shown below, which is due to the fact that Sqladmin class expects auth: GoogleAuth, which is defaulted to GoogleAuth<JSONClient>, where JSONClient = JWT | UserRefreshClient | BaseExternalAccountClient | ExternalAccountAuthorizedUserClient | Impersonated;

I believe that Sqladmin class should be parameterized with T extends AuthClient, and then it should accept GoogleAuth<T> in the auth property.

Code

import {AuthClient, GoogleAuth} from 'google-auth-library';
import {sqladmin_v1beta4} from '@googleapis/sqladmin';
const {Sqladmin} = sqladmin_v1beta4;

function buildSqlAdmin (authClient: AuthClient) {
  const auth = new GoogleAuth<AuthClient>({
    auth: authClient,
    scopes: ['https://www.googleapis.com/auth/sqlservice.admin'],
  });

  return new Sqladmin({
    auth
  });
}

TypeScript Error

Screenshot 2023-09-28 at 09 59 09

Type Definitions

Sqladmin:

GoogleAuth:

https://github.com/googleapis/google-auth-library-nodejs/blob/7030314c55c369acbda1873f649579b395ad07c8/src/auth/googleauth.ts#L85

@danielbankhead
Copy link
Member

Related:

The root of this request will be resolved here (for all googleapis libraries):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: sqladmin Issues related to the Cloud SQL Admin API API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants