Problem
I am working on JavaScript project using VSCode. I am using the UMD
design pattern and vscode intellisense cannot recognize the exports of a module from another file. I added all the declarations in a file called globals.d.ts
. Unfortunately I couldn't find a way to load the globals.d.ts
declarations from my JavaScript files.
Example Module declaration
export namespace ModuleName {
export interface Item {
toString(): string;
property: string;
name: string;
}
}
Example JavaScript File
(function (global, factory) {
"use strict";
if (typeof ModuleName === "undefined" && typeof require === "function") global.ModuleName = require("./mymodule.js");
if (typeof exports !== "undefined" && typeof module !== "undefined") factory(exports);
else factory(global.OtherModule = global.OtherModule || {});
})(this, (function (exports) {
"use strict";
function myMethod() {
}
exports.myMethod = myMethod;
return exports;
}));
What I tried
I tried using typings install "globals.d.ts"
which created the typings
folder, typings.json
etc. This was only working after opening the typings file in VSCode then closing and reopening the app. That only worked while I kept the typings
file open. This is not a very convenient way to add my interface declarations.
About VSCode (8 months ago)
Version: 1.17.0
Shell: 1.7.7
Node: 7.9.0
Architecture: x64
About VSCode (Now)
Version: 1.24.1
Shell: 1.7.12
Node: 7.9.0
Architecture: x64
There is no change in behavior.
npm i @types/[module]
instead – Diclinousincludes
in your tsconfig file – Diclinous/// references
for referencing the type files. – Diclinous@type
,@param
, and@returns
and intellisense will parse those. – HoldenVersion 1.24.1 (1.24.1)
, please upgrade first and then share your feedback – Houdon