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
Built-in Type Definitions TypeScript includes declaration files for all of the standardized built-in APIs available in JavaScript runtimes. This includes things like methods and properties of built-in types like string or function , top-level names like Math and Object , and their associated types.
The Node runtime does not ship with its own type definitions, so we need to import those types separately. Where can we find them? They are also in npm but need to be installed separately.
The exported type can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file. Here is an example of exporting a type from a file called another-file. ts .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With