Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .d.ts files

I have a project that I am using typescript in and want to use typescript definition files to interface with libraries such as mongoose. I have installed the appropriate .d.ts files via

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

I'm 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 at the moment, but when I transpile this 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'.

Either looking for a complete example on how to use these things (which sadly the docs are terrible at providing) or some pointers. Thanks.

like image 901
ed209 Avatar asked Dec 25 '22 03:12

ed209


2 Answers

Your reference tag is incorrect. You forgot to close it />. Fixed:

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

This will help you prevent such mistakes : https://github.com/TypeStrong/grunt-ts#references

like image 65
basarat Avatar answered Dec 27 '22 15:12

basarat


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

like image 39
Pranay Dutta Avatar answered Dec 27 '22 17:12

Pranay Dutta