Cannot find namespace 'google'.

Aperta
#1,209 4 commenti 2 reazioni 1 assegnatario Vedi su GitHub

@amuramoto ci sta già lavorando.

Dal 12/7/2022.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Operating system

macOS 12.04

Browser Version

Firefox 100.0.2

How severe is the bug?

moderate

Bug description

This bug is about the code excerpt from https://developers.google.com/maps/documentation/javascript/react-map#add-map

Using the given code block (see below), will lead to
Cannot find namespace 'google'. and Property 'google' does not exist on type 'Window & typeof globalThis'. The imports linked in this repository does also not solve the problem.

const ref = React.useRef<HTMLDivElement>(null);
const [map, setMap] = React.useState<google.maps.Map>();

React.useEffect(() => {
  if (ref.current && !map) {
    setMap(new window.google.maps.Map(ref.current, {}));
  }
}, [ref, map]);
Steps to reproduce

Follow the steps on https://developers.google.com/maps/documentation/javascript/react-map#typescript

Console log output
Uncaught TypeError: window.google is undefined
Source code as suggested by the guide
import React from 'react';
import { Wrapper, Status } from '@googlemaps/react-wrapper';

export const Map: React.FC<{}> = () => {
	const ref = React.useRef<HTMLDivElement>(null);
	const [map, setMap] = React.useState<google.maps.Map>();

	React.useEffect(() => {
		if (ref.current && !map) {
			setMap(new window.google.maps.Map(ref.current, {}));
		}
	}, [ref, map]);

	return <div ref={ref} />;
};

export const MyMap: React.FC = () => {
	return (
		<>
			<Map />
		</>
	);
};
Lingua principale
TypeScript
Stelle
804
Fork
826
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googlemaps/js-samples

Tutte le issue di googlemaps/js-samples

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.