0

How can I have type annotations to an import using the require() function? For instance I have this authenticate function from GCP Auth service:

const {authenticate} = require('@google-cloud/local-auth');

I see in the node_modules there's a index.d.ts file with type annotations for it:

import { OAuth2Client } from 'google-auth-library';
export interface LocalAuthOptions {
    keyfilePath: string;
    scopes: string[] | string;
}
export declare function authenticate(options: LocalAuthOptions): Promise<OAuth2Client>;

But when I try to use the functions it shows as type any. enter image description here

How can I add the type annotations to it?

João Pedro
  • 794
  • 2
  • 12
  • 28
  • Any reason you can't use import? – Ricky Mo May 24 '22 at 09:16
  • Related thread on vscode github issue: [https://github.com/microsoft/vscode/issues/77627](https://github.com/microsoft/vscode/issues/77627). And related SO post: [https://stackoverflow.com/questions/12742082/how-to-nodejs-require-inside-typescript-file](https://stackoverflow.com/questions/12742082/how-to-nodejs-require-inside-typescript-file) – Ricky Mo May 24 '22 at 09:19

0 Answers0