Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces do not check return type of methods when return is not called #4030

Open
fingerartur opened this issue Jan 9, 2023 · 2 comments
Labels
triage-done Has been reviewed by someone on triage rotation.

Comments

@fingerartur
Copy link

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;
@rishipal rishipal added the triage-done Has been reviewed by someone on triage rotation. label Jan 11, 2023
@rishipal
Copy link
Contributor

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.

@fingerartur
Copy link
Author

Confirmed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-done Has been reviewed by someone on triage rotation.
Projects
None yet
Development

No branches or pull requests

2 participants