title: Cannot find name 'google' angular 8
body: <p>As it shows error during build.<br></p>
  <blockquote>ERROR in app/pages/TestPage4/TestPage4.ts:27:27 - error TS2304: Cannot find name 'google'.
  <p>27       this.geoCoder = new google.maps.Geocoder;
  ~~~~~~
  app/pages/TestPage4/TestPage4.ts:29:32 - error TS2304: Cannot find name 'google'.</p>
  <p>29       const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement);
  ~~~~~~
  app/pages/TestPage4/TestPage4.ts:33:24 - error TS2503: Cannot find namespace 'google'.</p>
  <p>33           const place: google.maps.places.PlaceResult = autocomplete.getPlace();
  ~~~~~~</blockquote></p>
  <p>Here is my code below.<br></p>
  <pre><code>import { Component, OnInit, ElementRef, ViewChild, NgZone } from '@angular/core';
  import { MapsAPILoader } from '@agm/core';
  
  @Component({
    selector: 'app',
    templateUrl: './TestPage4.html',
    styleUrls: ['./TestPage4.css']
  })
  
  export class TestPage4 implements OnInit {
    lat: number;
    lng: number;
    zoom = 1;
    private geoCoder;
  
    @ViewChild('search', { static: false})
    public searchElementRef: ElementRef;
  
    constructor(
      private mapsAPILoader: MapsAPILoader,
      private ngZone: NgZone) {}
  
    ngOnInit() {
      //load Places Autocomplete
      
      this.mapsAPILoader.load().then(() =&gt; { 
        this.geoCoder = new google.maps.Geocoder;
  
        const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement);
        autocomplete.addListener(&quot;place_changed&quot;, () =&gt; {
          this.ngZone.run(() =&gt; {
            //get the place result
            const place: google.maps.places.PlaceResult = autocomplete.getPlace();
            console.log(place);
            //verify result
            if (place.geometry === undefined || place.geometry === null) {
              return;
            }
  
            for (var i = 0; i &lt; place.address_components.length; i++) {
              let addressType = place.address_components[i].types[0];
              //if (componentForm[addressType]) {
              //  var val = place.address_components[i][componentForm[addressType]];
              //  document.getElementById(addressType).value = val;
              //}
              // for the country, get the country code (the &quot;short name&quot;) also
              console.log(addressType);
              if (addressType == &quot;country&quot;) {
                console.log(place.address_components[i].short_name);
                console.log(place.address_components[i].long_name);
              }
              else{
                console.log('---others---');
                console.log(place.address_components[i].short_name);
                console.log(place.address_components[i].long_name);
              }
            }
  
            //set latitude, longitude and zoom
            this.lat = place.geometry.location.lat();
            this.lng = place.geometry.location.lng();
            this.zoom = 12;
          }); 
        });
      });
    }
  }
  </code></pre>
  <p>As i <strong>F12</strong> it <code>new google.maps.Geocoder</code> and shows me it exists here below.<br>
  <a href="https://i.stack.imgur.com/IDaZw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IDaZw.png" alt="enter image description here" /></a>
  But in reality when <strong>built</strong> it shows the above error.</p>
  <p><strong>Update 1:</strong><br></p>
  <pre><code>{
    &quot;compileOnSave&quot;: false,
    &quot;compilerOptions&quot;: {
      &quot;downlevelIteration&quot;: true,
      &quot;importHelpers&quot;: true,
      &quot;module&quot;: &quot;esnext&quot;,
      &quot;outDir&quot;: &quot;./dist/out-tsc&quot;,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: false,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;target&quot;: &quot;es5&quot;,
      &quot;typeRoots&quot;: [
        &quot;node_modules/@types&quot;
      ],
      &quot;lib&quot;: [
        &quot;es2017&quot;,
        &quot;dom&quot;
      ],
      &quot;baseUrl&quot;: &quot;src&quot;,
      &quot;paths&quot;: { &quot;@angular/*&quot;: [&quot;node_modules/@angular/*&quot;] }
    }
  }
  </code></pre>
  <p>This is the <strong>tsconfig.json</strong> file.</p>
  <p><strong>Update 2:</strong><br>
  Using <code>declare var google: any;</code> works on <br>
  <code>this.geoCoder = new google.maps.Geocoder;</code> and <br>
  <code>const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement);</code> but fails on <em>google.maps.places.PlaceResult</em> <strong>Cannot find namespace 'google'</strong> <code>const place: google.maps.places.PlaceResult = autocomplete.getPlace();</code></p>