Cannot find namespace 'google'.

未关闭
#1,209 4 条评论 2 个 reaction 已指派 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

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googlemaps/js-samples 的其他 Issue

查看 googlemaps/js-samples 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。