From e78e58c0c5a0dcf6675e671e2d54dcc46779744d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Py=C5=9Bk?= Date: Tue, 15 Jun 2021 18:54:14 +0200 Subject: [PATCH] feat: Support for @types/google.maps (#694) Fixes #690 --- .eslintrc.json | 11 ++---- README.md | 2 +- package-lock.json | 8 ++--- package.json | 2 +- packages/jest-mocks/src/map.ts | 8 +++++ packages/jest-mocks/src/marker.ts | 34 +++++-------------- packages/loader/src/loader.ts | 2 +- .../markerclustererplus/src/cluster-icon.ts | 12 ++++--- .../src/markerclusterer.ts | 2 +- .../markermanager/src/markermanager.test.ts | 2 +- packages/markermanager/src/markermanager.ts | 16 ++++++--- packages/ogc/src/wmsmaptype.test.ts | 2 +- packages/ogc/src/wmsmaptype.ts | 2 +- 13 files changed, 51 insertions(+), 52 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c8e1f219..1b912a92 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,14 +4,9 @@ "plugin:jest/recommended", "plugin:prettier/recommended" ], - "plugins": [ - "license-header" - ], + "plugins": ["license-header"], "rules": { - "license-header/header": [ - "error", - "../../header.js" - ] + "license-header/header": ["error", "../../header.js"] }, "parserOptions": { "ecmaVersion": 6, @@ -27,4 +22,4 @@ "env": { "browser": true } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 26747bd2..058918ac 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The following packages have never been officially published and are not maintain ## Other Resources - [Google Maps JS Documentation](https://developers.google.com/maps/documentation/javascript/tutorial) - [Google Maps JS Reference Documenations](https://developers.google.com/maps/documentation/javascript/reference/) -- [Google Maps Typings](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/googlemaps) - Community supported `npm i -D @types/googlemaps` +- [Google Maps Typings](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google.maps) - Community supported `npm i -D @types/google.maps` - [Google Maps JS Samples](https://github.com/googlemaps/js-samples) ## Support diff --git a/package-lock.json b/package-lock.json index 91d9bcf5..3c6c71f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3442,10 +3442,10 @@ "@types/node": "*" } }, - "@types/googlemaps": { - "version": "3.38.1", - "resolved": "https://registry.npmjs.org/@types/googlemaps/-/googlemaps-3.38.1.tgz", - "integrity": "sha512-6rVIwaJOKXAMzg+Cz22+fJkgQd8IMK8q9DBSL3Wg9GAffGCy71MdTEf+8T9bIa4mvC0DClEsyzwrOfuf9rM0Zg==", + "@types/google.maps": { + "version": "3.45.2", + "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.45.2.tgz", + "integrity": "sha512-3hKhaLt4EcKzssjmpIH8M12tN8WHp/gz7lh+85NdwXGtGSAjtiOEG4st9XdvaZkUHtlNaiAP2PlDbkNnNmD2NQ==", "dev": true }, "@types/istanbul-lib-coverage": { diff --git a/package.json b/package.json index 8f35d6a4..bc28129e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "devDependencies": { "@babel/preset-env": "^7.7.6", "@babel/runtime-corejs3": "^7.8.7", - "@types/googlemaps": "^3.38.1", + "@types/google.maps": "^3.45.2", "@types/jest": "^24.0.19", "@typescript-eslint/eslint-plugin": "^2.4.0", "@typescript-eslint/parser": "^2.0.0", diff --git a/packages/jest-mocks/src/map.ts b/packages/jest-mocks/src/map.ts index cef896fa..dc184e6c 100644 --- a/packages/jest-mocks/src/map.ts +++ b/packages/jest-mocks/src/map.ts @@ -60,6 +60,11 @@ export class Map_ extends MVCObject implements google.maps.Map { getProjection = jest .fn() .mockImplementation((): google.maps.Projection | null => jest.fn() as null); + getRenderingType = jest + .fn() + .mockImplementation( + (): google.maps.RenderingType => google.maps.RenderingType.RASTER + ); getStreetView = jest .fn() .mockImplementation( @@ -68,6 +73,9 @@ export class Map_ extends MVCObject implements google.maps.Map { ); getTilt = jest.fn().mockImplementation((): number => 0); getZoom = jest.fn().mockImplementation((): number => 0); + moveCamera = jest + .fn() + .mockImplementation((cameraOptions: google.maps.CameraOptions): void => {}); panBy = jest.fn().mockImplementation((x: number, y: number): void => {}); panTo = jest .fn() diff --git a/packages/jest-mocks/src/marker.ts b/packages/jest-mocks/src/marker.ts index cf3429d1..1ad034a3 100644 --- a/packages/jest-mocks/src/marker.ts +++ b/packages/jest-mocks/src/marker.ts @@ -19,7 +19,7 @@ import { LatLng } from "./index"; export class Marker extends MVCObject implements google.maps.Marker { static readonly MAX_ZINDEX: number; - constructor(opts?: google.maps.ReadonlyMarkerOptions) { + constructor(opts?: google.maps.MarkerOptions | null) { super(); } getAnimation = jest @@ -35,18 +35,12 @@ export class Marker extends MVCObject implements google.maps.Marker { getIcon = jest .fn() .mockImplementation( - (): - | string - | google.maps.ReadonlyIcon - | google.maps.ReadonlySymbol - | null - | undefined => null + (): string | google.maps.Icon | google.maps.Symbol | null | undefined => + null ); getLabel = jest .fn() - .mockImplementation( - (): google.maps.ReadonlyMarkerLabel | null | undefined => null - ); + .mockImplementation((): google.maps.MarkerLabel | null | undefined => null); getMap = jest .fn() .mockImplementation( @@ -83,18 +77,12 @@ export class Marker extends MVCObject implements google.maps.Marker { setIcon = jest .fn() .mockImplementation( - ( - icon: - | string - | google.maps.ReadonlyIcon - | google.maps.ReadonlySymbol - | null - ): void => {} + (icon: string | google.maps.Icon | google.maps.Symbol | null): void => {} ); setLabel = jest .fn() .mockImplementation( - (label: string | google.maps.ReadonlyMarkerLabel | null): void => {} + (label: string | google.maps.MarkerLabel | null): void => {} ); setMap = jest .fn() @@ -106,14 +94,12 @@ export class Marker extends MVCObject implements google.maps.Marker { .mockImplementation((opacity: number | null): void => {}); setOptions = jest .fn() - .mockImplementation( - (options: google.maps.ReadonlyMarkerOptions): void => {} - ); + .mockImplementation((options: google.maps.MarkerOptions): void => {}); setPosition = jest .fn() .mockImplementation( ( - latlng: google.maps.LatLng | google.maps.ReadonlyLatLngLiteral | null + latlng: google.maps.LatLng | google.maps.LatLngLiteral | null ): void => {} ); setShape = jest @@ -126,9 +112,7 @@ export class Marker extends MVCObject implements google.maps.Marker { .fn() .mockImplementation( ( - eventName: - | google.maps.MarkerChangeOptionEventNames - | google.maps.MarkerMouseEventNames, + eventName: string, handler: (this: Marker, event: MouseEvent) => void ): google.maps.MapsEventListener => (jest.fn() as unknown) as google.maps.MapsEventListener diff --git a/packages/loader/src/loader.ts b/packages/loader/src/loader.ts index 2ef0c7c1..76eb8d61 100644 --- a/packages/loader/src/loader.ts +++ b/packages/loader/src/loader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -/// +/// /* eslint-disable @typescript-eslint/no-explicit-any */ export interface LoaderOptions { diff --git a/packages/markerclustererplus/src/cluster-icon.ts b/packages/markerclustererplus/src/cluster-icon.ts index d2e1f882..7be365df 100644 --- a/packages/markerclustererplus/src/cluster-icon.ts +++ b/packages/markerclustererplus/src/cluster-icon.ts @@ -209,12 +209,16 @@ export class ClusterIcon extends OverlayViewSafe { // But it doesn't work with earlier releases so do a version check. if (gmVersion >= 332) { // Ugly version-dependent code - google.maps.event.addDomListener(this.div_, "touchstart", e => { - e.stopPropagation(); - }); + google.maps.event.addDomListener( + this.div_, + "touchstart", + (e: TouchEvent) => { + e.stopPropagation(); + } + ); } - google.maps.event.addDomListener(this.div_, "click", e => { + google.maps.event.addDomListener(this.div_, "click", (e: MouseEvent) => { cMouseDownInCluster = false; if (!cDraggingMapByCluster) { /** diff --git a/packages/markerclustererplus/src/markerclusterer.ts b/packages/markerclustererplus/src/markerclusterer.ts index 3d2629de..a378495c 100644 --- a/packages/markerclustererplus/src/markerclusterer.ts +++ b/packages/markerclustererplus/src/markerclusterer.ts @@ -293,7 +293,7 @@ export class MarkerClusterer extends OverlayViewSafe { public ariaLabelFn = this.options.ariaLabelFn || ((): string => ""); - private zIndex_ = this.options.zIndex || google.maps.Marker.MAX_ZINDEX + 1; + private zIndex_ = this.options.zIndex || +google.maps.Marker.MAX_ZINDEX + 1; private gridSize_ = this.options.gridSize || 60; private minClusterSize_ = this.options.minimumClusterSize || 2; private maxZoom_ = this.options.maxZoom || null; diff --git a/packages/markermanager/src/markermanager.test.ts b/packages/markermanager/src/markermanager.test.ts index 93a2cf94..22ddcdd1 100644 --- a/packages/markermanager/src/markermanager.test.ts +++ b/packages/markermanager/src/markermanager.test.ts @@ -15,7 +15,7 @@ */ /// -/// +/// /* eslint-disable @typescript-eslint/no-explicit-any */ import { MarkerManager } from "./markermanager"; diff --git a/packages/markermanager/src/markermanager.ts b/packages/markermanager/src/markermanager.ts index f622e622..99a57e39 100644 --- a/packages/markermanager/src/markermanager.ts +++ b/packages/markermanager/src/markermanager.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -/// +/// import { latLngToPixel } from "./utils"; import { GridBounds } from "./gridbounds"; @@ -210,9 +210,17 @@ class MarkerManager { // Tracking markers is expensive, so we do this only if the // user explicitly requested it when creating marker manager. if (this._trackMarkers) { - google.maps.event.addListener(marker, "changed", function(a, b, c) { - this._onMarkerMoved(a, b, c); - }); + google.maps.event.addListener( + marker, + "changed", + ( + marker: google.maps.Marker, + oldPoint: google.maps.LatLng, + newPoint: google.maps.LatLng + ) => { + this._onMarkerMoved(marker, oldPoint, newPoint); + } + ); } const gridPoint = this._getTilePoint( diff --git a/packages/ogc/src/wmsmaptype.test.ts b/packages/ogc/src/wmsmaptype.test.ts index ce9c9606..f3633751 100644 --- a/packages/ogc/src/wmsmaptype.test.ts +++ b/packages/ogc/src/wmsmaptype.test.ts @@ -15,7 +15,7 @@ */ /// -/// +/// import { initialize } from "@googlemaps/jest-mocks"; import { diff --git a/packages/ogc/src/wmsmaptype.ts b/packages/ogc/src/wmsmaptype.ts index fde108a6..7f60f0c9 100644 --- a/packages/ogc/src/wmsmaptype.ts +++ b/packages/ogc/src/wmsmaptype.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -/// +/// import { stringify } from "query-string"; /**