使用闭包编译器进行类型检查不是隐式的?

HMR*_*HMR 5 javascript strong-typing google-closure-compiler

我正在编译文件并获得编译代码,但注释似乎完全被忽略了; 没有警告没有错误.使用calcdeps.py使用以下命令编译我的代码:

set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\ ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\Mediator.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\DomDependent.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\WorkFlow.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\Messenger.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\data.js ^
--compiler_jar "D:\software\closure compiler\compiler.jar" ^
--output_mode compiled ^
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
--compiler_flags="--formatting=PRETTY_PRINT" ^
--output_file D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\main.js
pause
Run Code Online (Sandbox Code Playgroud)

例如在Messenger.js中我有一个函数:

/**
 * Replaces words in matches with a yes/no/all box
 * @param {Array} matches contains the items of myApp.data that matched words in text
 * @param {string} text contains the cleaned up user input (no html)
 */
myApp.Messenger.builtReplacewithOptions=function(matches,text){
Run Code Online (Sandbox Code Playgroud)

变量matches必须是一个Array,所有调用此函数的代码都使用Array调用它.要测试类型检查,我将Array更改为字符串,如下所示:

 * @param {string} matches contains the items of myApp.data that matched words in text
Run Code Online (Sandbox Code Playgroud)

再次编译但没有给出警告或错误.试图在批处理文件中向编译器添加一个参数:

--compiler_flags="--jscomp_warning=checkTypes" ^
Run Code Online (Sandbox Code Playgroud)

现在我收到警告.我的问题是:我是否必须开启各种检查?有没有办法让所有检查都开启,我只是明确地关闭了一些?

Fel*_*ing 7

您可以设置标志--warning_level=VERBOSE,相当于

--jscomp_warning=checkTypes --jscomp_error=checkVars \
--jscomp_warning=deprecated --jscomp_error=duplicate \
--jscomp_warning=globalThis --jscomp_warning=missingProperties \
--jscomp_warning=undefinedNames --jscomp_error=undefinedVars
Run Code Online (Sandbox Code Playgroud)

仍有一些检查将关闭,如果需要,您必须明确启用它们.默认情况下无法启用所有功能.

有关警告/错误类型的完整列表,请参阅https://code.google.com/p/closure-compiler/wiki/Warnings.