我创建了一个简单的 Angular 4/Typescript v2.1.6 应用程序。
我试图使用在 https://www.npmjs.com/package/@types/googlemaps 中指定的 googlemaps typescript 定义 (.d.ts 文件)。
我运行了以下命令:
当我执行
我得到了以下错误
tsconfig.json 的内容如下。(我也尝试过不使用 types/typeRoots 属性)
我可以确认文件index.d.ts也存在于位置node_modules/@types/googlemaps/index.d.ts。
我无法确定我缺少什么?
我运行了以下命令:
npm install --save @types/googlemaps
然后在我的 app.component.ts 文件中
import * as googlemaps from "googlemaps";
当我执行
npm start
我得到了以下错误
error TS2306: File '/home/dev/project/node_modules/@types/googlemaps/index.d.ts' is not a module.
我的tsconfig.json文件在src文件夹中,而node_modules文件夹与src文件夹处于同一级别,即:
/home/dev/project
|_src
|_app/
|_tsconfig.json
|_node_modules/
|_@types/
|_googlemaps/
tsconfig.json 的内容如下。(我也尝试过不使用 types/typeRoots 属性)
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2015",
"dom"
],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"../node_modules/@types"
],
"types": [
"googlemaps"
]
}
}
我可以确认文件index.d.ts也存在于位置node_modules/@types/googlemaps/index.d.ts。
我无法确定我缺少什么?