Specifying Eclipse / JSDT Javascript Variable Type

I am trying to use Eclipse to develop server side Javascript.

The API I use has a function doStuff(string, object)(names changed to protect the perpetrators) that returns the value of different types (subclasses of the same type) depending on the (values) of the arguments passed to them.

I created a Javascript library to describe this function:

/**
  * function doStuff(s, o)
  * @memberOf Global
  * @param {String} s
  * @param {Object} o
  * @type ResultType
  * @returns {ResultType}
  */
doStuff = function(str, obj} {return new ResultType();}

Since it can return multiple types, I declared it to return the base type. However, this means that Eclipse does not know what type it actually is, and therefore I get later false errors when trying to access the fields of this object.

So there could be FooResultType, BarResultType, each of which is ResultTypes, but has additional fields / functions

? - , , Eclipse , ?

( FooResultType)

/**
  * @type FooResultType
  */
  v = doStuff("stringvalue", someObject);

.

( , , , )

+5
1

( )

. , "var" - , JSDT, , . , JSDT , , , Javascript, .

/**
  * @returns {FooResultType}
  */
  var v = doStuff("stringvalue", someObject);

, @return, @type, , JSDT - . .

+7

All Articles