首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从`@types` typescript 2.0导入类型定义

如何从`@types` typescript 2.0导入类型定义
EN

Stack Overflow用户
提问于 2016-10-02 23:15:23
回答 3查看 35K关注 0票数 35

我在最新的ionic@RC.0构建过程中使用TypeScript2.0。

我安装了如下的google-maps类型:

npm install @types/google-maps --save-dev --save-exact

我正在尝试将一些类型定义导入到我的代码中,如下所示

代码语言:javascript
复制
/// <reference types="google-maps" />
import { LatLng, LatLngBounds } from 'google-maps';

但是我得到了这个打字错误:

./node_modules/@types/google-maps/index.d.ts has no exported member 'LatLng'

如果我查看源代码,我实际上在以下位置找到了定义

./node_modules/@types/google-maps/node_modules/@types/googlemaps/index.d.ts

EN

回答 3

Stack Overflow用户

发布于 2018-10-27 19:02:32

在项目根文件夹的tsconfig.json文件中添加对types包的引用:

代码语言:javascript
复制
"types": [
    "google-maps"
]

不要在源文件中导入任何内容,类型是全局定义的。

票数 12
EN

Stack Overflow用户

发布于 2017-11-29 14:02:35

import仅适用于当前包,而不适用于其依赖项。

所以你需要import { LatLng, LatLngBounds } from 'googlemaps'

票数 2
EN

Stack Overflow用户

发布于 2017-12-25 15:16:27

您检查了错误的声明文件。您正在使用的是:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/google-maps/index.d.ts,它不公开LatLng。

您链接到的声明文件是:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/googlemaps/index.d.ts

googlemaps vs google-maps

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39818429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档