The closure compiler a warning about a property that isn't defined on an extern when as far as I can tell the property is defined on that extern.
I would like to get the closure compiler to compile this cleanly without issuing this warning.
I am using the following options for the compiler:
- angular_pass
- compilation_level=ADVANCED_OPTIMIZATIONS
- create_source_map
- language_in=ECMASCRIPT5_STRICT
- manage_closure_dependencies
- warning_level=VERBOSE
The warning that is produced is:
trFilter.js:19: WARNING - Property instant never defined on pascalprecht.translate.$translate
target = $translate.instant(texts.toString());
^
The file that produces the warning has the following contents:
var myApp = {};
/*
* The trFilter generates translated strings.
*/
(function () {
'use strict';
/**
* @param {pascalprecht.translate.$translate} $translate
* @returns {function((Array.<string>|string)): string}
*/
var trFilter = function ($translate) {
return function(texts) {
var target;
target = $translate.instant(texts.toString());
return target;
};
};
myApp.trFilter = ['$translate', trFilter];
})();
angular.module('myApp')
.filter('tr', myApp.trFilter);
My extern for angular-translate contains the following:
/**
* @fileoverview Externs for Angular Translate.
* @externs
*/
/**
* Base namespace
* @type {Object}
* @const
*/
var pascalprecht = {};
goog.provide('pascalprecht');
/**
* angular-translate namespace
* @type {Object}
* @const
*/
pascalprecht.translate = {};
goog.provide('pascalprecht.translate');
/**
* The $translate service
* @constructor
*/
pascalprecht.translate.$translate;
goog.provide('pascalprecht.translate.$translate');
/**
* Returns a translation instantly from the internal state of loaded translation. All rules
* regarding the current language, the preferred language of even fallback languages will be
* used except any promise handling. If a language was not found, an asynchronous loading
* will be invoked in the background.
*
* @param {string} translationId Translation ID
* @param {Object=} interpolateParams Params
* @param {string=} interpolationId
*
* @return {string} translation
*/
pascalprecht.translate.$translate.instant = function (translationId, interpolateParams, interpolationId) {};
goog.exportProperty(pascalprecht.translate.$translate, 'instant', pascalprecht.translate.$translate.instant);
I don't think the goog.provide() and goog.exportProperty() calls are required in the extern file. I have tested with and without them in the file, but they don't seem to make any difference.
I am running closure using the grunt-closure-compiler grunt helper.
Changing to warning_level=QUIET does eliminate the warning, but it also eliminates warnings about things that would be an issue. For example, if I change the call to this:
target = $translate.instatn(texts.toString(());
I would like to get a warning, because there is no instatn() function on the $translate object.
What do I need to change to get the closure compiler to find the correct extern function in this case?