Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

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

like image 729
michael Avatar asked Oct 02 '16 15:10

michael


People also ask

What are type definitions in TypeScript?

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.

Do you need to install type definitions for node?

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.

How do you import export type?

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 .


1 Answers

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.

like image 181
Ropez Avatar answered Sep 25 '22 17:09

Ropez