简体   繁体   English

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

[英]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.

相关问题 如何排除TypeScript定义中声明的全局类型? - How do you exclude global types declared in TypeScript definitions? 如何根据 Redux 的类型定义在 TypeScript 中创建强类型的 redux 中间件? - How do you create strongly typed redux middleware in TypeScript from Redux's type definitions? 如何导入模块的 Typescript 类型以用于我自己的类型定义? - How can I import a module's Typescript types for use in my own type definitions? 在 Typescript 中,当数组包含不同的元素类型时,如何从数组类型中获取元素类型? - In Typescript how do you get an element type from an array type, when the array contains different element types? 打字稿类型定义的版本控制(@ types /) - Versioning for typescript type definitions (@types/) 从TypeScript定义导入解析和拒绝函数类型 - import resolve and reject function types from TypeScript definitions 如何在打字稿中使用递归类型定义 - How do use recursive type definitions in typescript 当类型定义未声明模块时,如何在TypeScript中导入库? - How to import a library in TypeScript when its type definitions do not declare a module? 如何知道 @types 中的 typescript 类型定义匹配实际的 package - How to know that typescript type definitions in @types match the actual package 在visual studio代码中,如何跳转到typescript类型定义index.d.ts中的实际代码? - In visual studio code, how do you jump to the actual code in a typescript type definitions index.d.ts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM