[英]How do you import type definitions from `@types` typescript 2.0
I'm using typescript 2.0 with the lastest ionic@RC.0
build process. 我正在使用最新的ionic@RC.0
构建过程的ionic@RC.0
2.0。
I installed the google-maps types like this: 我安装了google-maps类型,如下所示:
npm install @types/google-maps --save-dev --save-exact
and I'm trying to import some of the type definitions into my code like this 我正在尝试将一些类型定义导入到我的代码中
/// <reference types="google-maps" />
import { LatLng, LatLngBounds } from 'google-maps';
but I get this typescript error: 但我得到这个打字稿错误:
./node_modules/@types/google-maps/index.d.ts has no exported member 'LatLng'
and if I look in the source, I actually find the definition in 如果我查看源代码,我实际上找到了定义
./node_modules/@types/google-maps/node_modules/@types/googlemaps/index.d.ts
Add a reference to the types package in the file tsconfig.json
in the root folder of your project: 在项目的根文件夹中添加对tsconfig.json
文件中的types包的引用:
"types": [
"google-maps"
]
Don't import anything in your source files, the types are globally defined. 不要在源文件中导入任何内容,这些类型是全局定义的。
The import
only works for the current package, not its dependencies. import
仅适用于当前包,而不适用于其依赖项。
So you need to import { LatLng, LatLngBounds } from 'googlemaps'
所以你需要import { LatLng, LatLngBounds } from 'googlemaps'
You are checking the wrong declaration file. 您正在检查错误的声明文件。 The one you are using is: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/google-maps/index.d.ts which does not expose LatLng. 您使用的是: https : //github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/google-maps/index.d.ts ,它不会公开LatLng。
The declaration file you linked to is: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/googlemaps/index.d.ts 您链接的声明文件是: https : //github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/googlemaps/index.d.ts
googlemaps
vs google-maps
googlemaps
vs google-maps
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.