google / google/closure-compiler

Calling method without JSDoc comment -> could not determine type

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

Description

In compiling my project with "--jscomp_warning=reportUnknownTypes", I've noticed that calls to (at least some) methods with no JSDoc comment are reported as unknown types, even if they take no arguments and have no return value.

For example, this will trigger the warning:

```
/**
* @constructor
*/
function MyObject() {
this.close = function() {
console.log("bye bye");
};
}

...

myobject.close(); // <-- could not determine type of the expression
```

If I add an empty JSDoc comment, the warning persists:
```
function MyObject() {
/**
*
*/
this.close = function() {
console.log("bye bye");
};
}
```

But if I write anything in the comment, the warning goes away:
```
function MyObject() {
/**
* Huh?
*/
this.close = function() {
console.log("bye bye");
};
}

....

myobject.close(); // no more warning here!
```

Is this a bug? Shouldn't the compiler assume (or check and figure out) no parameters and no return value?

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.