在Ionic 3应用程序中找不到名称空间“ Google”

zue*_*est 2 typescript ionic-framework ionic2 ionic3

在尝试在我的项目中使用google变量后,有人可以帮助我解决此错误,并在Ionic 3应用程序中获取该错误,

npm install --save @ types / google-maps

这将以下内容添加到我的package.json中:

“ @ types / google-maps”:“ ^ 3.2.0”,

我也确实声明了声明var google;

并且做了 typings install dt~google.maps --global

然后我看到了这个灵魂,并尝试了一下,但是还是不起作用(注意,我生成了一个ios键和android键),尝试了这个 找不到名称空间“ google”

ionic cordova插件添加 https://github.com/mapsplugin/cordova-plugin-googlemaps#multiple_maps --variable API_KEY_FOR_ANDROID =“ YOUR_ANDROID_API_KEY_IS_HERE” -variable API_KEY_FOR_IOS =“ YOUR_IOS_API_KEY_IS_HERE” $ npm install --save地图

要点就是我的map.ts多数民众赞成在拍摄此错误:

https://gist.github.com/abdulfatah-ah1407281/25bc95352d0b1ba8e02b7d1e55cc7779

当我运行离子服务时出错:

Cannot find namespace 'google'.
C:/Users/pkhon/Desktop/k/ItBroken/src/components/map/map.ts
private map: google.maps.Map;
public isMapIdle:boolean;
Run Code Online (Sandbox Code Playgroud)

rob*_*b3c 5

您没有提到它,但是我猜您在Windows上。您使用的是ionic,在某些情况下(不知道是谁负责的,ionic或打字稿),平台存在差异,其中相同的tsconfig.json文件将在macos(也许是linux)上运行,但在Windows中却没有显式添加typeRoots条目compilerOptionstsconfig.json,例如:

// tsconfig.json
{
  "compilerOptions": {
    // ... other stuff
    "typeRoots": [ 'node_modules/@types' ]
  }
  // ... other stuff
}
Run Code Online (Sandbox Code Playgroud)