Reputation: 14241
I'm trying to import the node module, Q into my TypeScript project and would like to get Intellisense working 100%
This works, but q is set to any
, which means no intellisense. I also have to use a mix of Q and q, which can get confusing.
/// <reference path="Scripts/typings/q/Q.d.ts" />
module example {
// no intellisense on q
var q = require('q');
// we do get intellisense on deferred though
var deferred: Q.Deferred<void> = q.defer();
}
We can't do this because Q is a module, so the :Q
part results in an error.
/// <reference path="Scripts/typings/q/Q.d.ts" />
module example {
// BAD: this doesn't work
var q: Q = require('q');
}
File structure:
Q is in /node_modules/q/
Q.d.ts is in /Scripts/typings/q/Q.d.ts
I'm using Visual Studio 2013 SP4 and TypeScript 1.4
note: I've seen similar questions on stack, but those solutions don't work for the newer versions of typescript.
Upvotes: 1
Views: 1624
Reputation: 220974
var q: typeof Q = require('q');
Or, you can move the require
call outside the module
block and use `import instead:
import q = require('q');
Upvotes: 1