【问题标题】:Namespace 'google.maps.places' has no exported member 'AutocompleteService'命名空间“google.maps.places”没有导出成员“AutocompleteService”
【发布时间】:2020-01-15 04:16:30
【问题描述】:

我在这上面花了一个小时,我不知道还有什么可以尝试或阅读以找出问题所在。

我已将谷歌 api 库包含到项目中

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MY_KEY&libraries=places"></script>

和安装的类型

npm install --save @types/googlemaps

现在在我的服务中,我想使用来自 googlemap 库的类:

type AutocompletePrediction = google.maps.places.AutocompleteService.AutocompletePrediction;

typescript 用红色在AutocompleteService 下划线并表示:

Namespace 'google.maps.places' has no exported member 'AutocompleteService'.

但实际上当我检查谷歌打字定义时,我可以清楚地看到它。

这就是错误的样子

自动完成/建议效果很好

问题可能出在哪里? 任何提示表示赞赏,谢谢:)

我在 Mac OS 10.14.6 Mojave 上,使用 VScode 版本:1.41.1

PS:我不能忽略它,因为我的管道因同样的错误而中断:/

【问题讨论】:

    标签: typescript visual-studio-code


    【解决方案1】:

    我相信你想要type AutocompletePrediction = google.maps.places.AutocompletePrediction

    AutocompleteService 是一个类,而该类没有 AutocompletePrediction 成员。该错误消息可能令人困惑,因为 TS 通过对AutocompleteService.AutocompletePrediction 的访问看到并认为AutocompleteService 应该是一个命名空间

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-16
      • 2021-06-05
      • 2021-04-05
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      相关资源
      最近更新 更多