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 to share