Skip to content

Commit 08269ae

Browse files
authored
refactor(google-maps): clean up typing workarounds (#28418)
Now that we're on the non-legacy types internally, we can remove a bunch of workarounds.
1 parent fdd16e6 commit 08269ae

File tree

22 files changed

+92
-130
lines changed

22 files changed

+92
-130
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@angular/core": "^17.1.0-next.5",
6565
"@angular/forms": "^17.1.0-next.5",
6666
"@angular/platform-browser": "^17.1.0-next.5",
67-
"@types/google.maps": "^3.52.4",
67+
"@types/google.maps": "^3.54.10",
6868
"@types/youtube": "^0.0.46",
6969
"rxjs": "^6.6.7",
7070
"rxjs-tslint-rules": "^4.34.8",

src/google-maps/google-map/google-map.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {isPlatformBrowser} from '@angular/common';
3030
import {Observable} from 'rxjs';
3131
import {MapEventManager} from '../map-event-manager';
3232
import {take} from 'rxjs/operators';
33-
import {importLibrary} from '../import-library';
3433

3534
interface GoogleMapsWindow extends Window {
3635
gm_authFailure?: () => void;
@@ -313,9 +312,9 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
313312
this._initialize(google.maps.Map);
314313
} else {
315314
this._ngZone.runOutsideAngular(() => {
316-
importLibrary<typeof google.maps.Map>('maps', 'Map').then(mapConstructor =>
317-
this._initialize(mapConstructor),
318-
);
315+
google.maps
316+
.importLibrary('maps')
317+
.then(lib => this._initialize((lib as google.maps.MapsLibrary).Map));
319318
});
320319
}
321320
}

src/google-maps/import-library.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/google-maps/map-bicycling-layer/map-bicycling-layer.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import {Directive, EventEmitter, NgZone, OnDestroy, OnInit, Output, inject} from '@angular/core';
1313

14-
import {importLibrary} from '../import-library';
1514
import {GoogleMap} from '../google-map/google-map';
1615

1716
/**
@@ -45,12 +44,11 @@ export class MapBicyclingLayer implements OnInit, OnDestroy {
4544
this._initialize(this._map.googleMap, google.maps.BicyclingLayer);
4645
} else {
4746
this._zone.runOutsideAngular(() => {
48-
Promise.all([
49-
this._map._resolveMap(),
50-
importLibrary<typeof google.maps.BicyclingLayer>('maps', 'BicyclingLayer'),
51-
]).then(([map, layerConstructor]) => {
52-
this._initialize(map, layerConstructor);
53-
});
47+
Promise.all([this._map._resolveMap(), google.maps.importLibrary('maps')]).then(
48+
([map, lib]) => {
49+
this._initialize(map, (lib as google.maps.MapsLibrary).BicyclingLayer);
50+
},
51+
);
5452
});
5553
}
5654
}

src/google-maps/map-circle/map-circle.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {map, take, takeUntil} from 'rxjs/operators';
2424

2525
import {GoogleMap} from '../google-map/google-map';
2626
import {MapEventManager} from '../map-event-manager';
27-
import {importLibrary} from '../import-library';
2827

2928
/**
3029
* Angular component that renders a Google Maps Circle via the Google Maps JavaScript API.
@@ -179,12 +178,11 @@ export class MapCircle implements OnInit, OnDestroy {
179178
this._initialize(this._map.googleMap, google.maps.Circle, options);
180179
} else {
181180
this._ngZone.runOutsideAngular(() => {
182-
Promise.all([
183-
this._map._resolveMap(),
184-
importLibrary<typeof google.maps.Circle>('maps', 'Circle'),
185-
]).then(([map, circleConstructor]) => {
186-
this._initialize(map, circleConstructor, options);
187-
});
181+
Promise.all([this._map._resolveMap(), google.maps.importLibrary('maps')]).then(
182+
([map, lib]) => {
183+
this._initialize(map, (lib as google.maps.MapsLibrary).Circle, options);
184+
},
185+
);
188186
});
189187
}
190188
});

src/google-maps/map-directions-renderer/map-directions-renderer.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
const DEFAULT_DIRECTIONS: google.maps.DirectionsResult = {
1414
geocoded_waypoints: [],
1515
routes: [],
16+
request: {origin: 'foo', destination: 'bar', travelMode: 'BICYCLING' as google.maps.TravelMode},
1617
};
1718

1819
describe('MapDirectionsRenderer', () => {
@@ -64,6 +65,11 @@ describe('MapDirectionsRenderer', () => {
6465
it('gives precedence to directions over options', fakeAsync(() => {
6566
const updatedDirections: google.maps.DirectionsResult = {
6667
geocoded_waypoints: [{partial_match: false, place_id: 'test', types: []}],
68+
request: {
69+
origin: 'foo',
70+
destination: 'bar',
71+
travelMode: 'BICYCLING' as google.maps.TravelMode,
72+
},
6773
routes: [],
6874
};
6975
const directionsRendererSpy = createDirectionsRendererSpy({directions: updatedDirections});

src/google-maps/map-directions-renderer/map-directions-renderer.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
import {Observable} from 'rxjs';
2525
import {GoogleMap} from '../google-map/google-map';
2626
import {MapEventManager} from '../map-event-manager';
27-
import {importLibrary} from '../import-library';
2827

2928
/**
3029
* Angular component that renders a Google Maps Directions Renderer via the Google Maps
@@ -86,12 +85,11 @@ export class MapDirectionsRenderer implements OnInit, OnChanges, OnDestroy {
8685
this._initialize(this._googleMap.googleMap, google.maps.DirectionsRenderer);
8786
} else {
8887
this._ngZone.runOutsideAngular(() => {
89-
Promise.all([
90-
this._googleMap._resolveMap(),
91-
importLibrary<typeof google.maps.DirectionsRenderer>('routes', 'DirectionsRenderer'),
92-
]).then(([map, rendererConstructor]) => {
93-
this._initialize(map, rendererConstructor);
94-
});
88+
Promise.all([this._googleMap._resolveMap(), google.maps.importLibrary('routes')]).then(
89+
([map, lib]) => {
90+
this._initialize(map, (lib as google.maps.RoutesLibrary).DirectionsRenderer);
91+
},
92+
);
9593
});
9694
}
9795
}

src/google-maps/map-directions-renderer/map-directions-service.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ describe('MapDirectionsService', () => {
3737
});
3838

3939
it('calls route on inputs', () => {
40-
const result: google.maps.DirectionsResult = {routes: []};
40+
const result: google.maps.DirectionsResult = {
41+
routes: [],
42+
request: {
43+
origin: 'foo',
44+
destination: 'bar',
45+
travelMode: 'BICYCLING' as google.maps.TravelMode,
46+
},
47+
};
4148
const status = 'OK' as google.maps.DirectionsStatus;
4249
directionsServiceSpy.route.and.callFake((_request, callback) => {
4350
callback?.(result, status);

src/google-maps/map-directions-renderer/map-directions-service.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
/// <reference types="google.maps" />
1111

1212
import {Injectable, NgZone} from '@angular/core';
13-
import {importLibrary} from '../import-library';
1413
import {Observable} from 'rxjs';
1514

1615
export interface MapDirectionsResponse {
@@ -53,11 +52,8 @@ export class MapDirectionsService {
5352
if (google.maps.DirectionsService) {
5453
this._directionsService = new google.maps.DirectionsService();
5554
} else {
56-
return importLibrary<typeof google.maps.DirectionsService>(
57-
'routes',
58-
'DirectionsService',
59-
).then(serviceConstructor => {
60-
this._directionsService = new serviceConstructor();
55+
return google.maps.importLibrary('routes').then(lib => {
56+
this._directionsService = new (lib as google.maps.RoutesLibrary).DirectionsService();
6157
return this._directionsService;
6258
});
6359
}

src/google-maps/map-geocoder/map-geocoder.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
/// <reference types="google.maps" />
1111

1212
import {Injectable, NgZone} from '@angular/core';
13-
import {importLibrary} from '../import-library';
1413
import {Observable} from 'rxjs';
1514

1615
export interface MapGeocoderResponse {
@@ -49,12 +48,10 @@ export class MapGeocoder {
4948
if (google.maps.Geocoder) {
5049
this._geocoder = new google.maps.Geocoder();
5150
} else {
52-
return importLibrary<typeof google.maps.Geocoder>('geocoding', 'Geocoder').then(
53-
geocoderConstructor => {
54-
this._geocoder = new geocoderConstructor();
55-
return this._geocoder;
56-
},
57-
);
51+
return google.maps.importLibrary('geocoding').then(lib => {
52+
this._geocoder = new (lib as google.maps.GeocodingLibrary).Geocoder();
53+
return this._geocoder;
54+
});
5855
}
5956
}
6057

0 commit comments

Comments
 (0)