google / google/closure-compiler
const property declaration not inferred outside a constructor
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Even though a property declaration is recognized outside a constructor, a const property declaration is not. If the declaration is moved to the constructor the property type is recognized. Here is an example:
/*\* @constructor */
var TestThingie = function() {};
/*\* @return {number} */
TestThingie.prototype.log = function() { return 1 };
/*\* @constructor */
var CompilationTestController = function () {
this.init()
}
CompilationTestController.prototype.init = function() {
/*\* @type {!TestThingie} */
this.maybeLogger_ = new TestThingie();
/*\* @const */
this.maybeInferredLogger_ = new TestThingie();
};
CompilationTestController.prototype.maybeLogging_ = function() {
/*\* @type {null} _/ var x = this.maybeLogger_.log(); // WARNING
/_\* @type {null} */ var y = this.maybeInferredLogger_.log(); // NO WARNING
};
http://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540constructor%2520*%252F%250Avar%2520TestThingie%2520%253D%2520function()%2520%257B%257D%253B%250A%250A%252F**%2520%2540return%2520%257Bnumber%257D%2520*%252F%250ATestThingie.prototype.log%2520%253D%2520function()%2520%257B%2520return%25201%2520%257D%253B%250A%250A%252F**%2520%2540constructor%2520*%252F%250Avar%2520CompilationTestController%2520%253D%2520function%2520()%2520%257B%250A%2520%2520this.init()%250A%257D%250A%250ACompilationTestController.prototype.init%2520%253D%2520function()%2520%257B%250A%2520%2520%252F**%2520%2540type%2520%257B!TestThingie%257D%2520*%252F%250A%2520%2520this.maybeLogger_%2520%253D%2520new%2520TestThingie()%253B%250A%250A%2520%2520%252F**%2520%2540const%2520*%252F%250A%2520%2520this.maybeInferredLogger_%2520%253D%2520new%2520TestThingie()%253B%250A%257D%253B%250A%250ACompilationTestController.prototype.maybeLogging_%2520%253D%2520function()%2520%257B%250A%2520%2520%2520%252F**%2520%2540type%2520%257Bnull%257D%2520*%252F%2520var%2520x%2520%253D%2520this.maybeLogger_.log()%253B%2520%252F%252F%2520WARNING%250A%2520%2520%2520%252F**%2520%2540type%2520%257Bnull%257D%2520%2520*%252F%2520var%2520y%2520%253D%2520this.maybeInferredLogger_.log()%253B%2520%252F%252F%2520NO%2520WARNING%250A%257D%253B%26input1%26externs%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26MISSING_PROPERTIES%3D1
Contributor guide
Assessment
This issue has not been assessed yet.