我想编译这个Node.js模块(仅用于类型检查)
var externalRequire = require;
var Pool = externalRequire('pg-pool');
var config = {};
var pool = new Pool(config);
module.exports = {};
使用这些Closure编译器的选项:
java -jar compiler.jar
--js_output_file output.js
--use_types_for_optimization
--warning_level VERBOSE
--jscomp_warning=reportUnknownTypes
--jscomp_warning=checkTypes
--compilation_level ADVANCED_OPTIMIZATIONS
--process_common_js_modules
--externs externs.js
--js src.js
externs.js只包含一个定义:
/**
* @param name
* @return {*}
*/
var require = function(name) {}
问题在于我不知道如何向Closure编译器解释" Pool"不是对象的实例,而是键入。
src.js:5: WARNING - cannot instantiate non-constructor
var pool = new Pool(config);
^
src.js:5: WARNING - could not determine the type of this expression
var pool = new Pool(config);
^
0 error(s), 2 warning(s), 88,9% typed
如何避免这些错误?