Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 496111

Summary: Add JSDoc proposals for 'any' and 'an object'
Product: [ECD] Orion Reporter: Michael Rennie <Michael_Rennie>
Component: JS ToolsAssignee: Curtis Windatt <curtis.windatt.public>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: curtis.windatt.public
Version: 12.0   
Target Milestone: 13.0   
Hardware: All   
OS: All   
Whiteboard:

Description Michael Rennie CLA 2016-06-14 10:53:31 EDT
Currently in code you can define the type of a param / return / type tag as 'Object' (OK). What you are likely really trying to say is 'an object', not the built-in type 'Object'.

For example, say you have:

/**
 * @returns {Object} Something
 */
function foo() {}

You are in effect saying you are returning the built-in type Object vs. 'an object'.

To support this subtlety, Tern allows you to define named types (which we already can complete in assist), the any type - ? and an empty object - {}. So to say your function returns just 'an object' the above example would be re-written as:

/**
 * @returns {?} Something
 */
function foo() {}

or

/**
 * @returns {{}} Something
 */
function foo() {}

You can also provide property names in the second update like the following:

/**
 * @returns {{one: number, two: string}} Something
 */
function foo() {}

The confusion of the this subtlety can be seen when the unknown member expression rule is enabled - you will see a bunch of warnings like 'foo is undefined for Object' - which is correct, because Object.prototype does not contain foo.

To help avoid this confusion, we should provide two extra proposals in our JSDoc support: '?' and '{}'