I'm trying to create a Node.js application which will connect to a MongoDb database. I'm using TypeScript. But the following lines of code are troublesome.
/// <reference path="mongodb.d.ts" />
var mongo = require('mongodb');
class DefaultModel<T> {
private db : mongo.Db;
}
TSC reports that: TS2095: Could not find symbol 'mongo'.. I don't understand why it cannot find it as it was declared just outside the class. Can you help me figure out why?
The module is declared in mongodb.d.ts as declare module "mongodb" { /* Omitted */ }
TS2095: Could not find symbol 'mongo'.
You are trying to use it in the type delaration space : :mongo.Db;. And you only have it declared in the variable declaration space : var mongo
Fix: use import not var:
/// <reference path="mongodb.d.ts" />
import mongo = require('mongodb');