How to use @types/[library] in a component?


#1

Hello ! =).

I am a beginner in Ionic 2 and TypeScript, and i try to despair to use the external library “geolib” during two day. (https://github.com/manuelbieh/Geolib) in my project with @types/geolib.

I have read lot of forum about that, but nothing work for me… I know i am probably a noob ^^".

So i have do :

npm install --save @types/geolib

and in my component i try to use it like that :

import * as Geolib from "geolib";

Result error : File ‘/Users/***/Lab/[project name]/node_modules/@types/geolib/index.d.ts’ is not a module.

I have try too with

/// <reference path="..." /> and /// <reference type="..." />

My tsconfig.json :

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": [
            "dom",
            "es2015"
        ],
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": true,
        "target": "es5"
    },
    "include": [
        "src/**/*.ts"
    ],
    "exclude": [
        "node_modules"
    ],
    "compileOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}

Someone can explain me what I do wrong ? Thanks


#2

It looks like that library has TypeScript definitions included with it, so I would get rid of that @types/geolib for starters.


#3

My bad … You right ! it’s work, thanks rapropos :grin:

I juste need to do :

npm install geolib

And import with :

import * as Geolib from 'geolib';