I am setting up a node.js project that uses a native add-on. The native add-on includes a large number of exported functions. I've setup a typings file (.d.ts
) that includes all the function definitions and data etc. that are exported from the native add-on. When I pack all of this up with npm, and install it into the client project, the vscode intellisense picks up all the types and all is well.
When I try to use the typings for a test.js
in the same project as the native add-on, the typings are not being picked up, specifically the exported variables; I suspect it has something to do with the way they are exported in the .d.ts
, or the naming of the module in the .d.ts
.
In the .d.ts
, I have the exports listed as;
interface MyI {
Initiate() : void;
}
module 'modulename' {
export var i : MyI;
}
I require
the module in the client as (.js
file);
var i = require("modulename");
In the test code, I require it as (since I stub it through a index.js
file);
var i = require("./index.js");
The index.js
in turn looks like;
var i = require("./lib/nativeaddon");
module.exports.i = i;
How to I get vscode to use the typings, locally, for the intellisense when I use the add-on (via the index.js
) for the test.js
?
test.ts
, nottest.js
since the javascript would not have any TS-aware intellisense. And you wouldn't see anything unless you have anindex.d.ts
file defined. If you changed toindex.ts
, things would be different, though. – Andrew Eisenbergindex.d.ts
solves the intellisense issue, thanks (I previously named it after the package name). Do you have a reference for that? I'm still getting to grips with the typescript stuff and that solution didn't occur to me. Would be able to write it up as an answer? – Niall