michael
michael

Reputation: 4547

How do you import type definitions from `@types` typescript 2.0

I'm using typescript 2.0 with the lastest [email protected] build process.

I installed the google-maps types like this:

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

Upvotes: 43

Views: 47291

Answers (3)

Ropez
Ropez

Reputation: 3514

Add a reference to the types package in the file tsconfig.json in the root folder of your project:

"types": [
    "google-maps"
]

Don't import anything in your source files, the types are globally defined.

Upvotes: 17

Sam
Sam

Reputation: 15350

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.

The declaration file you linked to is: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/googlemaps/index.d.ts

googlemaps vs google-maps

Upvotes: 2

jifeng.yin
jifeng.yin

Reputation: 2151

The import only works for the current package, not its dependencies.

So you need to import { LatLng, LatLngBounds } from 'googlemaps'

Upvotes: 2

Related Questions