Specifying to Eclipse/JSDT the type of a Javascript variable -


i'm trying use eclipse server-side javascript development.

the api use has function dostuff(string, object) (names changed protect guilty) returns value of differing types (subclasses of 1 type) depending on (values of) arguments passed it.

i have built javascript library describe function:

/**   * function dostuff(s, o)   * @memberof global   * @param {string} s   * @param {object} o   * @type resulttype   * @returns {resulttype}   */ dostuff = function(str, obj} {return new resulttype();} 

because can return several types, have declared returning base type. however, means eclipse doesn't know type is, , later spurious errors when trying access fields of object.

so there can fooresulttype, barresulttype, each of resulttypes, have additional fields/functions

is there way around this? can somehow annotate variable holding returned value eclipse knows type is?

i've tried (with , without braces around fooresulttype)

/**   * @type fooresulttype   */   v = dostuff("stringvalue", someobject); 

but makes no difference.

(there other questions in area, nothing address issue, think)

(answering own question)

the below work. key seems "var" - declaring variable can jsdt recognise has specified type. suspicion jsdt can manage 1 type per variable, although of course being javascript type can change arbitarily.

/**   * @returns {fooresulttype}   */   var v = dostuff("stringvalue", someobject); 

it seems require @returns rather @type, although it's difficult know , not supported jsdt - it's not documented , experimentation needed. small changes seem make unexpected differences sometimes.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -