TypeScript错误:找不到命名空间"google" [英] TypeScript Error: Cannot find namespace 'google'

查看:955
本文介绍了TypeScript错误:找不到命名空间"google"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有angular-cli项目

I have project angular-cli

〜root〜/src/typings.json

{
  "globalDevDependencies": {
    "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
  },
  "globalDependencies": {
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
    "google.maps": "registry:dt/google.maps#3.20.0+20160914131659"
  }
}

〜root〜/typings/index.d.ts

/// <reference path="globals/angular-protractor/index.d.ts" />
/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="globals/google.maps/index.d.ts" />
/// <reference path="globals/hammerjs/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/selenium-webdriver/index.d.ts" />

〜root〜/src/tsconfig.json

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types",
      "../typings"
    ],
    "files": [
      "../typings/index.d.ts"
    ]
  }
}

运行后 ng投放 我在控制台中有错误消息

After run ng serve I have error message in console

[默认]错误 F:〜root〜\ src \ app \ ui \ google-map \ map-marker \ map-marker.directive.ts:7:26

ERROR in [default] F:~root~\src\app\ui\google-map\map-marker\map-marker.directive.ts:7:26

找不到命名空间"google"

Cannot find namespace 'google'

[默认]错误 〜root〜\ src \ app \ trip-entry-page \ trip-entry-page.component.ts:188:21

ERROR in [default] ~root~\src\app\trip-entry-page\trip-entry-page.component.ts:188:21

找不到名称"google"

Cannot find name 'google'

〜root〜\ src \ app \ ui \ google-map \ map-marker \ map-marker.directive.ts:7:26

... 
@Input() veyoMapMarker: google.maps.MarkerOptions 
...

〜root〜\ src \ app \ trip-entry-page \ trip-entry-page.component.ts:188:21

... 
if (status === google.maps.DirectionsStatus.OK) { 
...

构建应用正确运行后

我如何解决此错误消息?

How me resolve this Error messages?

推荐答案

反应迟了一点,但使用 Angular CLI RC.0 遇到了类似的问题.

A bit of a late response but I had a similar issue using Angular CLI RC.0.

原来,我还没有安装并导入类型,可以按照以下步骤进行操作:

It turned out that I hadn't install and imported the typings, which can be done as follows:

npm install --save-dev @types/googlemaps

import {} from '@types/googlemaps';

这篇关于TypeScript错误:找不到命名空间"google"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆