TKoL
TKoL

Reputation: 13892

Force Intellisense to recognize Assigned Variable Types

I have an asynchronous function which returns an array of 4 sub-arrays. I then split up that array into variables. I'm trying to get intellisense to recognize these new variables but it's not really working:

asyncGet().then(function(results){
    // results is an array of 4 arrays

    /// <var name="arrayOfA" type="Array" elementType="A" />
    var arrayOfA = results[0];
    /// <var name="arrayOfB" type="Array" elementType="B" />
    var arrayOfB = results[1];
    /// <var name="arrayOfC" type="Array" elementType="C" />
    var arrayOfC = results[2];
    /// <var name="arrayOfD" type="Array" elementType="D" />
    var arrayOfD = results[3];
})

As you can see I've tried to document the variables with standard XML intellisense documentation, but I'm not getting any of the intellisense on arrayOfA to arrayOfD.

However, if I keep the documentation and the variable initializations, but without assigning the variables anything, I get appropriate intellisense.

eg

    /// <var name="arrayOfA" type="Array" elementType="A" />
    var arrayOfA;

arrayOfA will get intellisense there, but obviously at this point won't be assigned the actual results.

Upvotes: 0

Views: 508

Answers (1)

justaguess
justaguess

Reputation: 11

It seems like what you could try is document the structure of the result itself by using the "value" parameter.

E.g.

asyncGet().then(function(results){
    /// <param name="results" value="{0:new A(), 1:new B(), 2:new C(), 3:new D()}">four-part return array</param>

The "value" XML comment is a misnomer -- it causes Intellisense to directly execute the Javascript literal you pass to determine the type structure of the identifier (sorry if my notation is a little rusty).

No guarantees it'll work, just a guess. Check Documenting Arrays in JSDoc TypeDefs (34864291) to see an example of this under function process_response(response).

Once you give the proper type information to the results array, then maybe it won't confuse Intellisense when you assign it to the ArrayOf variables.

Upvotes: 1

Related Questions