Not possible to suppress warning on initializing WebAssembly object
/**
* @suppress{checkTypes, duplicate, const}
*/
var WebAssembly = {};
$ google-closure-compiler --compilation_level ADVANCED_OPTIMIZATIONS --language_in ECMASCRIPT_2020 --language_out NO_TRANSPILE --emit_use_strict=false --js a.js --js_output_file tmp5qadu4_7.cc.js --formatting PRETTY_PRINT
externs.zip//webassembly.js:29:18: WARNING - [JSC_TYPE_MISMATCH] initializing variable
found : {
CompileError: (typeof WebAssembly.CompileError),
Exception: (typeof WebAssembly.Exception),
Instance: (typeof WebAssembly.Instance),
LinkError: (typeof WebAssembly.LinkError),
Memory: (typeof WebAssembly.Memory),
Module: (typeof WebAssembly.Module),
RuntimeError: (typeof WebAssembly.RuntimeError),
Table: (typeof WebAssembly.Table),
Tag: (typeof WebAssembly.Tag),
compile: function((ArrayBuffer|ArrayBufferView)): Promise<WebAssembly.Module>,
...
}
required: {}
29| var WebAssembly = {};
^^
0 error(s), 1 warning(s), 100.0% typed
Two out of the three suppressions work, avoiding a warning on const-ness and duplication, but the checkTypes does not avoid the JSC_TYPE_MISMATCH warning on initializing variable found.
Are you trying to polyfill WebAssembly?
If so, then you should probably do something like this:
var WebAssembly = WebAssembly || createMyWebAssemblyPolyfill();
If you type createmyWebAssemblyPolyfill() correctly, I think you may be able to avoid the need to suppress anything.
Thanks @brad4d , yes, this is for polyfilling WebAssembly. (In the emscripten project we have a mode that emits wasm compiled to JS, for older environments without wasm support, and in that mode we have a minimal replacement for the WebAssembly global object, to avoid writing entirely different startup code for the two modes, basically.)
It looks like returning the object from a function works around the issue here, even without adding any type info on that function - thanks! However it also increases code size in my measurements, so for now we might keep ignoring this warning for now.