title: How to get automatically created Javascript variable in Typescript?
body: <p>I'm trying to overcome an issue with using a Google login API in react.</p>
  
  <p>The issue is caused by the user already having a logged in session, meaning the API isn't needed and can be ignored. The solution in <strong>Javascript</strong> looks like this:</p>
  
  <pre><code>const auth = gapi.auth2.getAuthInstance();
  
  if (!auth.isSignedIn.get()) {
     auth.signIn().then(() =&gt; 
          // Do login stuff
      );
  } else {
     // Get old signIn data
  }
  </code></pre>
  
  <p>The problem here is in the first line. The <code>gapi</code> variable is created after an automatic call to the Google login API. Dynamic typing seems to be useful here, because it just finds <code>gapi</code> as required. </p>
  
  <p>Problem is I'm using <strong>Typescript</strong>, so the above code needs to have hard typing. It's therefore giving an error:</p>
  
  <p><code>Error: (TS) Cannot find name 'gapi'</code></p>
  
  <p>How can I tell Typescript that gapi will exist? </p>
  
  <p>I've had similar before with values that could be null, which I overcome via</p>
  
  <pre><code>if(value == null){
      //do nothing
  } else {
      //use the value;
      }
  </code></pre>
  
  <p>but the problem here is that I'd be saying <code>if(gapi == null)</code> which still gives the <code>Cannot find name gapi</code> error.</p>
  
  <p>Is there a know workaround for telling Typescript that it's going to be looking for and using a javascript variable created by an external source/API?</p>
  
  <p>Thanks.</p>