Fix useMap return type (#2262)

This commit is contained in:
Xiaoji Chen 2023-08-21 11:25:11 -07:00 committed by Xiaoji Chen
parent 63c15208c9
commit a212f1358e

View File

@ -52,10 +52,12 @@ export const MapProvider: React.FC<{children?: React.ReactNode}> = props => {
);
};
export function useMap<MapT extends MapInstance>(): {
export type MapCollection<MapT extends MapInstance> = {
[id: string]: MapRef<MapT> | undefined;
current?: MapRef<MapT>;
} {
};
export function useMap<MapT extends MapInstance>(): MapCollection<MapT> {
const maps = useContext(MountedMapsContext)?.maps;
const currentMap = useContext(MapContext);
@ -63,5 +65,5 @@ export function useMap<MapT extends MapInstance>(): {
return {...maps, current: currentMap?.map};
}, [maps, currentMap]);
return mapsWithCurrent as {current?: MapRef<MapT>; [id: string]: MapRef<MapT> | undefined};
return mapsWithCurrent as MapCollection<MapT>;
}