JSDoc and WebStorm - Override type of a function parameter field, JSDoc best practices

Plop!


A piece of code will be clearer than a long text:

/**
* @typedef {generalObject} GeneralObject
* @type {Object}
* @property {Object} generalField
*/
var generalObject = {
  generalField : {}
};

/**
* @typedef {specificObject} SpecificObject
* @type {GeneralObject}
* @extends {GeneralObject}
* @property {Object} specificField
*/
var specificObject = Object.create(generalObject, {
  specificField : {
    value : {}
  }
});

/**
* @typedef {exampleContainer} Container
* @type {Object}
* @property {GeneralObject} object1
*/
var exampleContainer = {
  object1 : Object.create(generalObject)
};

/**
* @param {Container} container
*/
function doSomething(container) {
  //container.object1.//Auto-completed with 'generalField' as expected
}

/**
* @param {Container} container
* @param {SpecificObject} container.object1
*/
function doSomethingSpecific(container) {
  //container.object1.//Not auto-completed with 'specificField'
}




In this example, we have:
A type GeneralObject pointing to generalObject,
A type SpecificObject pointing to specificObject and prototyped on generalObject,
A type Container pointing to exampleContainer which has a generalObject typed field,
A function doSomething which takes a Container as a parameter,
A function doSomethingSpecific which takes a Container as a parameter but need the Container's field to be of type SpecificField rather than generalField.


As the comments state, auto-completion breaks in the last scenario. Is there any way to get it working?
Considering that this example was voluntarily simplified for the purpose of readability, is this kind of thing a good thing to do in JSDoc or should I take another approach?
Plus, WebStorm seems conflicted as to what container.object1 is:
http://puu.sh/fUusH/f3ee57348a.pnghttp://puu.sh/fUuK3/c5a1bdf6ed.png

I attached the example code.
Thanks in advance for your help.



Attachment(s):
JSDoc and WebStorm - Override type of a function parameter field.js

Please sign in to leave a comment.