相关疑难解决方法(0)

@ types/googlemaps/index.d.ts'不是模块

我想在我的Angular项目中使用Google Maps API,因此我使用这两个命令来安装npm包:

npm install @agm/core --save-dev
npm install @types/googlemaps --save-dev
Run Code Online (Sandbox Code Playgroud)

我将此行添加到我的组件中:

import {} from "@types/googlemaps";
Run Code Online (Sandbox Code Playgroud)

但是我在VS Code中看到了这两个错误:

[ts] File 'h:/Angular Projects/Breakfast/client/breakfast/node_modules/@types/googlemaps/index.d.ts' is not a module.
[ts] Cannot import type declaration files. Consider importing 'googlemaps' instead of '@types/googlemaps'.
Run Code Online (Sandbox Code Playgroud)

我添加了这些行

"types": ["googlemaps"]
"moduleResolution": "node"
Run Code Online (Sandbox Code Playgroud)

到tsconfig.json和tsconfig.spec.json,但仍然没有运气.在Chrome开发工具上,我看到以下错误:

Error: Uncaught (in promise): TypeError: Cannot read property 'Autocomplete' of undefined
TypeError: Cannot read property 'Autocomplete' of undefined
Run Code Online (Sandbox Code Playgroud)

角度版本6打字稿版本2.9.2

我也尝试过Angular 5.

typescript angular-cli angular angular-cli-v6

54
推荐指数
7
解决办法
3万
查看次数

TypeScript错误:找不到命名空间'google'

我有项目angular-cli

〜根〜/ 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"
  }
}
Run Code Online (Sandbox Code Playgroud)

〜根〜/分型/ 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" />
Run Code Online (Sandbox Code Playgroud)

〜根〜/ 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": [ …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli typescript-typings angular

5
推荐指数
2
解决办法
1万
查看次数