0

I wanted to use the Google's JS API, so I included it into my index.html and installed the typings with typings install dt~gapi --global --save

My IDE (Webstorm), shows me that the variable gapi has auth and client as function, but it shows me no sub-functions of these two. When I include /// <reference path="../../../typings/globals/gapi/index.d.ts" /> at the top of my Service everything works.

/// <reference path="../../../typings/globals/gapi/index.d.ts" />
export class foo {
  constructor() {
    gapi.auth.authorize({
      //my config  
    });
  }
}

So did I miss anything or is this the right way?

2
  • I'm having (I think) the same problem. Can you add some code? Commented Oct 7, 2016 at 11:21
  • Added some code Commented Oct 7, 2016 at 11:31

1 Answer 1

1

I came across this issue recently, here are some configurations that worked for me:

I'm using DefinitelyTyped @types/gapi package.

npm install --save-dev @types/gapi

From typescript docs, use /// <reference types="..." /> directive to load types in your typescript file:

/// <reference types="gapi" />

Additional configurations I have in tsconfig.json file at the root of my project:

{
  ...
  "compilerOptions": {
    // I thought this was enough to recognize the types
    // but that was not the case
    "typeRoots": ["node_modules/@types"],
    ...
  }
}

Make sure you use typescript v2.0 or later.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.