Search code examples
typescriptangularionic2hammer.js

How to import the type-definition in typescript?


I tried use the type-definition for hammerjs. As:

import Hammer from 'hammerjs';

But i get this error:

Error TS2307: Cannot find module 'hammerjs'

I have two question. First, is necessary get all files of tile definition in github, our i can get the simples definition for hammerjs?

My package.json contains:

"dependencies": {
   "git+https://[email protected]/DefinitelyTyped/DefinitelyTyped.git"
}

The second question, whats my error about import module?


Solution

  • I resolve the problem after read: http://x-team.com/2016/06/include-javascript-libraries-in-an-ionic-2-typescript-project/

    I installed hammerjs with the command:

    typings install github:DefinitelyTyped/DefinitelyTyped/hammerjs/hammerjs.d.ts#de8e80dfe5360fef44d00c41257d5ef37add000a --global --save

    Then still appeared the error:

    Error TS2307: Cannot find module 'hammerjs'

    I am development the app with ionic2, i found that the compiler of typescript look the file main.d.ts and not index.d.ts. After rename the file index.d.ts to main.d.ts and works fine! The file main.d.ts found in root-your-app/typings

    For import in the project i use: import * as Hammer from 'hammerjs';