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

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

问题描述

我有项目 angular-cli

~root~/src/typings.json

<代码>{globalDevDependencies":{"angular-protractor": "注册表:dt/angular-protractor#1.5.0+20160425143459","jasmine": "注册表:dt/jasmine#2.2.0+20160621224255","selenium-webdriver": "注册表:dt/selenium-webdriver#2.44.0+20160317120654"},全局依赖":{"es6-shim": "注册表:dt/es6-shim#0.31.2+20160602141504","google.maps": "注册表:dt/google.maps#3.20.0+20160914131659"}}

~root~/typings/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

<代码>{编译器选项":{声明":假,emitDecoratorMetadata":真,"experimentalDecorators": 真,"lib": ["es6", "dom"],"mapRoot": "./",模块":es6","moduleResolution": "节点","outDir": "../dist/out-tsc","sourceMap": 真,"目标": "es5",类型根":["../node_modules/@types",../打字"],文件":[../typings/index.d.ts"]}}

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

<块引用>

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

找不到命名空间google"

<块引用>

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

找不到名称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

<预><代码>...如果(状态 === google.maps.DirectionsStatus.OK){...

构建应用程序正常工作后

我如何解决此错误消息?

解决方案

回复有点晚,但我在使用 Angular CLI RC.0 时遇到了类似的问题.

原来是我没有安装导入typings,可以这样做:

npm install --save-dev @types/googlemaps从@types/googlemaps"导入 {};

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"
    ]
  }
}

After run ng serve I have error message in console

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

Cannot find namespace 'google'

and

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

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) { 
...

After build app correct working

How me resolve this Error messages?

解决方案

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';

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

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