具有静态字段的函数的闭包编译器外部

Closure Compiler Externs for Function with static fields

使用 Google 的闭包编译器在函数对象上也有属性的构造函数的正确类型是什么?

这是对 Closure compiler debugger 的第一次尝试。

申请代码

const Mocha = /** @type {!MochaJS} */ (require('mocha'));

const mochaInstance = new Mocha();
const Suite = Mocha.Suite;

外部闭包

/** @constructor */
const MochaJS = function() {};

/** @type {!MochaJS.Suite} */
MochaJS.prototype.Suite;

/** @record */
MochaJS.Suite = function() {};

困难来自于闭包编译器不能很好地处理外部模块定义。另外,不要将 constructor/namespace 与实例混淆。他们是不同的。

申请

// A constructor type for Mocha
const Mocha = /** @type {!function(new:MochaJS)} */ (require('mocha'));
const mochaInstance = new Mocha();

const Suite = /** @type {!MochaJSSuite} */ (Mocha.Suite);

外部人员

/** @constructor */
const MochaJS = function() {};

/** @function */
MochaJSSuite = function() {};

这只是对类型的粗略猜测 - 我对 Mocha 不够熟悉,无法在不查找文档参考的情况下编写外部函数。希望它能为您指明正确的方向。