Cannot find namespace 'google'.

Đang mở
#1,209 4 bình luận 2 reaction 1 người được giao Xem trên GitHub

@amuramoto đang làm issue này rồi.

Từ ngày 12/7/2022.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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 />
		</>
	);
};
Ngôn ngữ chính
TypeScript
Star
804
Fork
826
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googlemaps/js-samples

Tất cả issue của googlemaps/js-samples

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.