How to use .d.ts files

I have a project where I am using typescript and want to use typescript definition files to interact with libraries like mongoose. I have installed the relevant .d.ts files via

tsd query mongoose --action install
tsd query node --action install

      

I am trying to import mongoose via the following code

///<reference path="../typings/mongoose/mongoose.d.ts">
import mongoose = require("mongoose");

class MongooseUser
{
    constructor()
    {

    }

    useMongoose():any {
        return mongoose.Collection;
    }
}

      

Obviously I'm not trying to do anything here right now, but when I go over I get the following errors:

Unable to resolve external module '"mongoose"'.
Module cannot be aliased to a non-module type.
error TS2095: Could not find symbol 'mongoose'.

      

Look for a complete example on how to use these things (which, unfortunately, the docs are terrible when provided) or some pointers. Thank you.

+3


source to share


2 answers


Your link tag is incorrect. You forgot to close it />

. Fixed:

///<reference path="../typings/mongoose/mongoose.d.ts"/>

      



This will help you prevent errors like this: https://github.com/TypeStrong/grunt-ts#references

+6


source


d.ts is your definition file it has nothing to do with the mongoose package, it is only for intellisense, are you sure mongoose is installed in your module_node, please check and install it locally as well as globally



+2


source







All Articles