Skip to content

Commit

Permalink
fix(google-maps): resolve mismatching types (#30544)
Browse files Browse the repository at this point in the history
Due to some infrastructure issues, we can't import the real types for the marker clusterer. We work around it by copying some of them into the repository which has caused an issue where the external types no longer align with the internal ones. This change resolves the issue by converting a few classes to interfaces.

Fixes #30466.

(cherry picked from commit 2b7133b)
  • Loading branch information
crisbeto committed Feb 25, 2025
1 parent 69d6bb3 commit 81aa285
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
28 changes: 9 additions & 19 deletions src/google-maps/map-marker-clusterer/map-marker-clusterer-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,15 @@ export interface ClusterOptions {
markers?: Marker[];
}

export declare class Cluster {
export interface Cluster {
marker?: Marker;
readonly markers?: Marker[];
protected _position: google.maps.LatLng;
constructor({markers, position}: ClusterOptions);
get bounds(): google.maps.LatLngBounds | undefined;
get position(): google.maps.LatLng;
/**
* Get the count of **visible** markers.
*/
get count(): number;
/**
* Add a marker to the cluster.
*/
bounds?: google.maps.LatLngBounds;
position: google.maps.LatLng;
count: number;
push(marker: Marker): void;
/**
* Cleanup references and remove marker from map.
*/
delete(): void;
new (options: ClusterOptions): Cluster;
}

export declare class MarkerClusterer extends google.maps.OverlayView {
Expand Down Expand Up @@ -117,11 +107,11 @@ export interface Renderer {
render(cluster: Cluster, stats: ClusterStats, map: google.maps.Map): Marker;
}

export declare class ClusterStats {
readonly markers: {
export interface ClusterStats {
markers: {
sum: number;
};
readonly clusters: {
clusters: {
count: number;
markers: {
mean: number;
Expand All @@ -130,7 +120,7 @@ export declare class ClusterStats {
max: number;
};
};
constructor(markers: Marker[], clusters: Cluster[]);
new (markers: Marker[], clusters: Cluster[]): ClusterStats;
}

export interface Algorithm {
Expand Down
23 changes: 13 additions & 10 deletions tools/public_api_guard/google-maps/google-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ export type AriaLabelFn = (text: string) => string;
export type Calculator = (markers: google.maps.Marker[], clusterIconStylesCount: number) => ClusterIconInfo;

// @public (undocumented)
export class Cluster {
constructor({ markers, position }: ClusterOptions);
export interface Cluster {
// (undocumented)
new (options: ClusterOptions): Cluster;
// (undocumented)
bounds?: google.maps.LatLngBounds;
// (undocumented)
count: number;
// (undocumented)
get bounds(): google.maps.LatLngBounds | undefined;
get count(): number;
delete(): void;
// (undocumented)
marker?: Marker;
// (undocumented)
readonly markers?: Marker[];
// (undocumented)
get position(): google.maps.LatLng;
position: google.maps.LatLng;
// (undocumented)
protected _position: google.maps.LatLng;
push(marker: Marker): void;
}

Expand Down Expand Up @@ -107,10 +109,11 @@ export interface ClusterOptions {
}

// @public (undocumented)
export class ClusterStats {
constructor(markers: Marker[], clusters: Cluster[]);
export interface ClusterStats {
// (undocumented)
new (markers: Marker[], clusters: Cluster[]): ClusterStats;
// (undocumented)
readonly clusters: {
clusters: {
count: number;
markers: {
mean: number;
Expand All @@ -120,7 +123,7 @@ export class ClusterStats {
};
};
// (undocumented)
readonly markers: {
markers: {
sum: number;
};
}
Expand Down

0 comments on commit 81aa285

Please sign in to comment.