Search code examples
javascriptgoogle-closure-compilerjsdoc3

Usage of @public JsDoc tag along with @export leads to a warning


I am trying to compile code using closure compiler and generate public only documentation using JsDoc.

Why is the use of @public and @export tags at the same time prohibited? There is also an unit test checking it.

/**
 * @public
 * @export
 */
function hello(name) {
  alert('Hello, ' + name);
}
hello('New user');

When trying to compile that, closure compiler throws a warning:

JSC_PARSE_ERROR: Parse error. extra visibility tag at line 4 character 3 * @export

Here is an example using online closure compiler.

As mentioned here about @public:

Indicates that a member or property is public. A property marked @public is accessible to all code in any file. This is the implicit default and rarely used. This is not used to indicate that name should be preserved in obfuscating builds see @export.

So how can I indicate that I want a particular symbol to be both public and exported?


Solution

  • The error is telling you that @public is implied by @export.

    Exporting something implies it will be used by external code, and that implies that the item must be public.

    In my experience, you'll likely only need to know one thing about @public and that is from a portion in the question:

    [...]This is the implicit default and rarely used[...]