Cannot find namespace 'google'.

オープン
#1,209 コメント 4 件 リアクション 2 件 担当者 1 名 GitHub で見る

@amuramoto がすでに取り組んでいます。

2022年7月12日 から。

評価

この issue はまだ評価されていません。

説明

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 />
		</>
	);
};
主要言語
TypeScript
スター
804
フォーク
826
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googlemaps/js-samples のほかの issue

googlemaps/js-samples の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。