【发布时间】:2019-07-27 14:27:14
【问题描述】:
我目前正在使用 VisualStudioCode 编写一个 nodejs 应用程序,并且我正在使用 doc cmets 将函数的参数链接到类,以便 IntelliSense 可以启动,但是当我想使用的类/类型时遇到了一些问题模块。
我目前的处理方式:
class Foo{
constructor(){
this.bar = "value"
}
}
/**
* @param {Foo} parameter
*/
function foobar(parameter){
parameter.bar.charAt(0); //parameter.bar now with IntelliSense
}
在foobar 中,我现在可以看到我可以在bar 上调用的所有可用属性/函数。
现在,如果在节点模块的某个地方有一个 TypeScript 文件:
declare module 'coollib' {
namespace lib {
type CoolLibType = {
begin?: string | number | Date;
liveBuffer?: number;
requestOptions?: {};
highWaterMark?: number;
lang?: string;
}
}
export = lib;
}
我如何引用这个?我想在我的 JavaScript 文件中做这样的事情:
const CoolLibType = require('coollib')
/**
* @param {CoolLibType} obj
*/
function foobar(obj){
obj.lang.charAt(0); //with cool IntelliSense
}
但它显然不能这样工作。
【问题讨论】:
-
为什么不完全用 typescript 编写应用程序,然后使用 TS-Node 之类的东西来构建任何 Javascript 文件?
-
我对 TypeScript 有所了解。我宁愿继续使用 JavaScript。
标签: javascript node.js typescript visual-studio-code intellisense