1

I'm using agm and trying to make naming shortcuts for googleapi by using namespaces aliases in typescript:

//general
export import GoogleMap = google.maps.Map;

export import GoogleStyleOptions = google.maps.Data.StyleOptions;
//map
export import GoogleStyledMapType = google.maps.StyledMapType;
//drawing:
export import GoogleDrawingManager = google.maps.drawing.DrawingManager;
export import GoogleOverlayCompleteEvent = google.maps.drawing.OverlayCompleteEvent;
export import GoogleOverlayType = google.maps.drawing.OverlayType;
export import GoogleCircle = google.maps.Circle;
export import GoogleFeature = google.maps.Data.Feature;
//events:
export import GoogleMouseEvent = google.maps.MouseEvent;
export import GoogleDataMouseEvent = google.maps.Data.MouseEvent;
//places:
export import GoogleAutoComplete = google.maps.places.Autocomplete;
export import GooglePlaceResult = google.maps.places.PlaceResult;

so instead of writing:

@Component({
  selector: 'app-google-map',
//....
 initDrawingManager(map: google.maps.Map): void {
    this.drawingManager = new google.maps.drawing.DrawingManager({
//....

i could write:

@Component({
  selector: 'app-google-map',
//....
 initDrawingManager(map: GoogleMap): void {
    this.drawingManager = new GoogleDrawingManager({
//....

i'm receiving the error

google-map.model.ts:2 is the google-map.model.ts:2 - the file were i specify the namespaces aliases i though i could load the aliases file before the MapModule boostrap but it didn't work, i assume because that file get loaded even before that?:

export function initializeMapApiImports(
  mapsAPILoader: MapsAPILoader,
): () => Promise<void> {
  return () => mapsAPILoader.load()
}

@NgModule({
  declarations: [
    MapComponent,
    GoogleMapComponent,
    DataLayerMouseEventDirective
  ],
  imports: [
    CommonModule,
    CoreViewModule,
    AgmCoreModule.forRoot({
      apiKey: '...',
      libraries: ['places', 'drawing']
    }),
  ],
  providers: [
    { provide: APP_INITIALIZER, useFactory: initializeMapApiImports, deps: [MapsAPILoader], multi: true }
  ]
})
export class MapModule { }

0 Answers0