dgeni-packages
dgeni-packages copied to clipboard
Error parsing the jsdoc type expression "{number| {function(row?:any,index?:number): number}}"
I'm trying to document a property that returns a number or a function - this seems to work with pure jsdocs but not here
* @type {number|function(row?:any,index?:number): number}
The property is defined as follows.
@Input() rowHeight: (number | ((row?: any, index?: number) => number)) = 0;
If I removing the ?'s it works, but I believe they will no longer appear as optional parameters.
Any suggestions on how we can work around this?
@dalelotts - can you give me a bit more information. Is it the @type tag that is not working? What is being output?
The library we use to parse the types is https://github.com/hegemonic/catharsis Perhaps this doesn't support this notation?
Call stack here:
Error: Error parsing the jsdoc type expression "{number|function(row?:any,index?:number): number}"
at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/services/transforms/extract-type.js:56:15
at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:166:19
at arrayEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:537:11)
at Function.forEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:9359:14)
at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:165:11
at Object.tagDef.getProperty (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:54:17)
at readTags (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:138:22)
at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:86:11
at arrayEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:537:11)
at Function.forEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:9359:14)
at tagExtractor (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:65:9)
OK, I'll take a look...
Right! I can reproduce this in a unit test. It look like catharsis does not like this syntax...
@dalelotts - it seems that you are using an invalid syntax. The correct syntax should not include the parameter names. For example the following test passes in dgeni-packages:
it('should handle optional function params', function() {
value = '{number|function(?any,?number): number} some description';
value = transform(doc, tag, value);
expect(tag.typeList).toEqual([ 'number', 'function(?any, ?number): number' ]);
});
See https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#optional-argument-in-a-function-type for more information.