|
| 1 | +/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-explicit-any */ |
| 2 | + |
| 3 | +import {DOMAttributes, RefAttributes} from 'react'; |
| 4 | + |
| 5 | +// add an overload signature for the useMapsLibrary hook, so typescript |
| 6 | +// knows what the 'maps3d' library is. |
| 7 | +declare module '@vis.gl/react-google-maps' { |
| 8 | + export function useMapsLibrary( |
| 9 | + name: 'maps3d' |
| 10 | + ): typeof google.maps.maps3d | null; |
| 11 | +} |
| 12 | + |
| 13 | +// temporary fix until @types/google.maps is updated with the latest changes |
| 14 | +declare global { |
| 15 | + namespace google.maps.maps3d { |
| 16 | + interface Map3DElement extends HTMLElement { |
| 17 | + mode?: 'HYBRID' | 'SATELLITE'; |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// add the <gmp-map-3d> custom-element to the JSX.IntrinsicElements |
| 23 | +// interface, so it can be used in jsx |
| 24 | +declare module 'react' { |
| 25 | + namespace JSX { |
| 26 | + interface IntrinsicElements { |
| 27 | + ['gmp-map-3d']: CustomElement< |
| 28 | + google.maps.maps3d.Map3DElement, |
| 29 | + google.maps.maps3d.Map3DElement |
| 30 | + >; |
| 31 | + } |
| 32 | + |
| 33 | + interface IntrinsicElements { |
| 34 | + ['gmp-marker-3d']: CustomElement< |
| 35 | + google.maps.maps3d.Marker3DElement, |
| 36 | + google.maps.maps3d.Marker3DElement |
| 37 | + >; |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +// a helper type for CustomElement definitions |
| 43 | +type CustomElement<TElem, TAttr> = Partial< |
| 44 | + TAttr & |
| 45 | + DOMAttributes<TElem> & |
| 46 | + RefAttributes<TElem> & { |
| 47 | + // for whatever reason, anything else doesn't work as children |
| 48 | + // of a custom element, so we allow `any` here |
| 49 | + children: any; |
| 50 | + } |
| 51 | +>; |
0 commit comments