问题
我正在使用VSCode进行JavaScript项目开发。我使用UMD
设计模式,但是vscode智能感知无法识别来自另一个文件的模块的导出。我在一个名为globals.d.ts
的文件中添加了所有声明。不幸的是,我找不到一种方法从我的JavaScript文件中加载globals.d.ts
声明。
示例模块声明
export namespace ModuleName {
export interface Item {
toString(): string;
property: string;
name: string;
}
}
JavaScript文件示例
(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;
}));
我尝试的
我尝试使用typings install "globals.d.ts"
命令,这创建了typings
文件夹、typings.json
等文件。但只有在打开VSCode编辑器并关闭再重新打开应用程序后才能正常工作。而且只有在保持typings
文件处于打开状态时才能正常工作,这不是一种很方便的添加接口声明的方式。
关于VSCode(8个月前)
Version: 1.17.0
Shell: 1.7.7
Node: 7.9.0
Architecture: x64
关于 VSCode(现在)
Version: 1.24.1
Shell: 1.7.12
Node: 7.9.0
Architecture: x64
行为没有改变。
npm i @types/[模块名]
来代替。” - PitaJ@type
,@param
和@returns
来描述,智能感知将解析它们。 - christophersw