JSDocs / Intellisense question WS9
I have the property of a class declared in the constructor like this:
/**
* Associative array of GridConfig class
* @name View#grids
* @type {Object.<string, GridConfig>}
*/
this.grids={};
From google docs {Object.<string, GridConfig>} should declare grids as an associative array with string key and values of type B
and I am using it somewhere like this:
view.grids.grdResults.refresh();
So intellisense correctly picks up views and it also notes grids as implicitly defined, it has no intellisense for grdResults and for refresh just finds everything in the app that has a refresh method
What I want is for the intellisense to realize that grdResults is of type GridConfig and detect its refresh method, is this the right way to declare it?
Tks
Rob
Please sign in to leave a comment.
Please provide the full code sample. Your Object type should be marked as generic type using '@template A,B' annotation to be able to be instantiated as
....... LOTS OF OTHER PROPERTIES.......
}
I am not really sure that @template is appropriate here.
The type of value in the grids associate array never changes it will always be a GridConfig , similarly the forms array will always hold HTMLFormElements.
From what I read of @template it is where the type might vary so you specify it at the point it is instantiated, but in this case there might be 20 View objects but in every case grids property is always an associative array holding objects of type GridConfig, what varies with each instance is the name i.e. the key
Haven't heard of such syntax - please can you point me to the corresponding documentation? From Google JSDoc documentation, @type {Foo.<string>} syntax is used for creating instance of generic type Foo (https://developers.google.com/closure/compiler/docs/js-for-compiler#generics).
WebStorm supports JSDoc generic types, but has no idea of associative arrays holding objectsbeing used as types
https://developers.google.com/closure/compiler/docs/js-for-compiler
{Array.<string>}An array of strings.
{Object.<string, number>}An object in which the keys are strings and the values are numbers.
Actually it seems WS9 does support this JSDocs syntax in one way:
views.grids['myGrid'].refresh()
but not if I do this
views.grids.myGrid.refresh()
in the first case it correctly realizes ['myGrid'] is a GridConfig class and provides intellisense for it, in the second case it does not.
So WS9 can actually document associative arrays containing a single type but only if you reference using array index syntax ['aName'] rather direct accessing the value with dot notation .aName which most people are going to do.