3

Is there a way to make a correct description for a property with special symbols like "+" in jsdoc?

Example:

/**
  * @typedef {Object} TestObject
  * @property {string} "id+name"
  */

"id+name" seems to be an invalid syntax in this case.

shadeglare
  • 6,136
  • 5
  • 46
  • 54

1 Answers1

-1

You need to review what is the @property according to documentation. Basically this is variable name inside a class. Right? In this case you should follow JS convention for variable names. This is the reference to the post discover it ... What characters are valid for JavaScript variable names?. Obviously the variable name "id+name" is not valid. The following are accessors to this property ...

TestObject.id+name // fail
TestObject["id+name"] // would work for most of the browsers

The question to JSDoc creators, how they verify properties of specific type @property tag. I strongly believe they would point on the same JS convention for variable names. Sure enough you may not accept it as the answer on your question. Maybe somebody else or somebody from JSDoc team will provide with better idea.

Community
  • 1
  • 1
Slava Ivanov
  • 6,359
  • 2
  • 22
  • 34
  • 1
    Second one is a valid accessor by the way and that's the point. – shadeglare Mar 15 '17 at 16:32
  • @shadeglare Yes, you right this would work with most of the browsers, but JSDoc doesn't like it, so does intellisense wouldn't understand what to display when type "TestObject.". Not sure that a reason to create the variables like that. Just for the matter of theory? Anyway, thanks for pointing, I'll modify the answer. – Slava Ivanov Mar 15 '17 at 16:41