javascript - Using @typedef to define a specific function type - Stack Overflow

I don't know how much of this (if any) is related to Google Closure or if it's all clean jsdo

I don't know how much of this (if any) is related to Google Closure or if it's all clean jsdoc, but I tried using @typedef to define a specific type of function like this;

/**
 * @typedef {function(paramType0, paramType1):returnType} name.space.and.TypeName
 */

also tried

/**
 * @typedef {function(paramType0, paramType1):returnType} 
 */
name.space.and.TypeName;

where param and return types are the reason I want to define this specification of function. My question is this;

Why do validation tell me that the "Method is not of Function type". I know it's an option to use the type 'Function', but as far as I know, that won't allow me to define parameter and return types? Am I wrong on this as well?

I would much appreciate some assistance on this in any case. Thanks.

I don't know how much of this (if any) is related to Google Closure or if it's all clean jsdoc, but I tried using @typedef to define a specific type of function like this;

/**
 * @typedef {function(paramType0, paramType1):returnType} name.space.and.TypeName
 */

also tried

/**
 * @typedef {function(paramType0, paramType1):returnType} 
 */
name.space.and.TypeName;

where param and return types are the reason I want to define this specification of function. My question is this;

Why do validation tell me that the "Method is not of Function type". I know it's an option to use the type 'Function', but as far as I know, that won't allow me to define parameter and return types? Am I wrong on this as well?

I would much appreciate some assistance on this in any case. Thanks.

Share Improve this question asked Apr 6, 2015 at 15:20 NinjaToolNinjaTool 631 silver badge5 bronze badges 1
  • Sounds like you are miss using the typedef, how are you using the declared type? (The second form is more correct). – John Commented Apr 9, 2015 at 0:19
Add a ment  | 

1 Answer 1

Reset to default 5

Typical use of a typedef looks like this:

/** @typedef {function():string} */
var SomeFunctionType;

/** @param {SomeFunctionType} x This is a function */
function useFunction(x) {
  ...
}

The question is lacking some detail and I expect you actually want a @type declaration to type a value, rather than creating a type name:

/** @type {function():string} */
var someFunction = getFunctionFromSomewhere();

someFunction();

An overview of the jsdoc annotation can be found here: https://developers.google./closure/piler/docs/js-for-piler

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744867345a4598053.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信