0
我试图使用Tern对某些Javascript代码执行类型推断。但是,类型推断似乎并没有在代码中使用JSDoc注释。Tern无法使用JSDoc类型信息
我使用代码/** @type {Foo} */ let x;
作为问题的示例。在Tern website's demo page(使用CodeMirror)上,编辑器能够推断出x
的类型为Foo
。
然而,当通过节点本地运行时,我得到了这个:{ type: '?', exprName: 'x' }
。
下面是复制问题的一个片段:
const tern = require('tern');
const ternServer = new tern.Server({
plugins: {
doc_comment: {
strong: true
}
}
});
const js = `/** @type {Foo} */ let x;`;
ternServer.addFile("main", js);
ternServer.request({
query: {
type: "type",
file: "main",
start: js.length - 2,
end: js.length - 2
}
}, console.log);
燕鸥以其他方式工作了类型推断完美的罚款。这是使用JSDoc注释的时候,它似乎没有用我初始化和调用它的方式工作。
我甚至将doc_comment
插件设置为strong
,这意味着JSDoc类型比通常推断的类型更受欢迎,但无济于事。
任何想法如何让这个工作?