google / google/closure-compiler

Interfaces do not check return type of methods when `return` is not called

Open
#4,030 2 comments 0 reactions 0 assignees View on GitHub
triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Interfaces do not check return type of methods when `return` is not called.

```js
/** @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;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.