closure-compiler
closure-compiler copied to clipboard
Interfaces do not check return type of methods when `return` is not called
Interfaces do not check return type of methods when return
is not called.
/** @interface */
function ISerializable() {};
/** @type {function(): string} */
ISerializable.prototype.serialize;
/**
* @implements {ISerializable}
* @constructor
*/
function Car() {}
Car.prototype.serialize = function() {}
// Does not produce error, and it should. The interface says this method
// must return a string, yet it returns void and there is no error
The interface says method serialize
must return a string, yet it returns void and there is no error. There should be an error.
Compiler Version: v20221102
Build command:
java -jar ./scripts/closureCompiler.jar \
--entry_point=./src/js/index.js \
--js=./src/**.js \
--dependency_mode=PRUNE \
--warning_level=VERBOSE \
--js_output_file=./dist/bundle.js \
--module_resolution=WEBPACK \
--compilation_level=ADVANCED \
--jscomp_error=checkDebuggerStatement \
--jscomp_error=unusedLocalVariables \
--jscomp_error=reportUnknownTypes \
--jscomp_error=strictCheckTypes;
Note: This only happens for empty functions since their return type is looser. This should report as expected for non-empty functions even with no return.
Confirmed