4
votes

I have created a simple Angular 4/Typescript v2.1.6 application. I am trying to use the googlemaps typescript definition (.d.ts file) as specified at https://www.npmjs.com/package/@types/googlemaps

I ran the command

npm install --save @types/googlemaps

Then in my app.component.ts

import * as googlemaps from "googlemaps";

When I execute

npm start

I get the following error

error TS2306: File '/home/dev/project/node_modules/@types/googlemaps/index.d.ts' is not a module.

my tsconfig.json file is in the src folder and the node_modules folder is at the same level as src i.e:

/home/dev/project
  |_src
    |_app/
    |_tsconfig.json
  |_node_modules/
    |_@types/
      |_googlemaps/

The contents of tsconfig.json are as follows. (I have also tried without the types/typeRoots properties)

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2015",
      "dom"
    ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": [
      "googlemaps"
    ]
  }
}

I can confirm that the file index.d.ts also exists at the location node_modules/@types/googlemaps/index.d.ts

I can't work out what I am missing?

1

1 Answers

0
votes

I installed a old version of Typescript and it worked!!

I had typescript 2.9 and i installed the 2.6 because the new version validates difference the modules. Or thing similar.

npm install [email protected]

I hope to help you. Regards.